USB Networking/zh cn

From Openmoko

(Difference between revisions)
Jump to: navigation, search
 
Line 1: Line 1:
 
= Neo1973 side =
 
= Neo1973 side =
  
== Name resolution ==
+
== 命名方式 ==
  
By default Neo1973 has usb0 interface working due to Ethernet gadget (g_ether) compiled into kernel.
+
预设的状况下Neo1973拥有usb0界面,被编译到kernel中,做为以太网络装置。
 
+
在Neo上,如果你想要在网络上使用完整的主机名称,你必须定义你的DNS server。建立 /etc/resolv.conf档案,档案中要包含以下的内容:
On the Neo, if you want to reach out to the internets using full qualified hostnames, you need to define your DNS server. Create a file /etc/resolv.conf with at least one line saying
+
  
 
  nameserver xxx.xxx.xxx.xxx
 
  nameserver xxx.xxx.xxx.xxx
Line 11: Line 10:
 
e.g. nameserver 192.168.1.1
 
e.g. nameserver 192.168.1.1
  
Then you can also easily update your 2007.2 OpenMoko packages with "ipkg update && ipkg upgrade" on the Neo.
+
因此,你也可以轻松的使用 "ipkg update && ipkg upgrade" 更新 Neo.
 +
<br><br>
 +
更好的方法是编辑: /etc/network/interfaces 并且写入以下的内容:<br><br>
 +
<code>
 +
up echo nameserver 192.168.0.200 >/etc/resolv.conf
 +
</code><br>
 +
要指定你喜好的DNS server而不是192.168.0.200。
 +
<br><br>
 +
example:  <code>up echo nameserver 4.2.2.2 >/etc/resolv.conf</code>
 +
 
  
A better approach is to symlink
+
另一个方法是symlink  (NOW OBSOLETE?)
  
 
  ln -s /var/run/resolv.conf /etc/resolv.conf
 
  ln -s /var/run/resolv.conf /etc/resolv.conf
  
and fill the file at bootup with a script /etc/network/if-up.d/08setupdns containing:
+
并且在启动 /etc/network/if-up.d/08setupdns script中写入:
  
 
  #!/bin/sh -e
 
  #!/bin/sh -e
 
  echo  nameserver 192.168.0.200 > /var/run/resolv.conf
 
  echo  nameserver 192.168.0.200 > /var/run/resolv.conf
  
this way the file is correctly handled from ppp package when dialing into gprs.
+
使用这个方法可以在拨号到GPRS时,正确的从ppp 软件中处理。
  
 
== Routing ==
 
== Routing ==
  
You need a additional route for traffic to the internet. This traffic can be routed through your pc (see below) if the pc is the default route destination. you can achieve this by adding
+
你必须自额外的流量绕送到因特网上。 若你的计算机是预设的目的地位置,这个流量可以透过你的计算机被绕送出去 (see below)。你可以使用下列方法达到这个目地:
  
  gateway 10.10.10.21
+
  gateway 192.168.0.200
  
to your /etc/network/interfaces in the usb0 section.
+
在usb0区段中到 /etc/network/interfaces。
  
 
= Desktop side =
 
= Desktop side =
  
== Manual method ==
+
== 手动 ==
  
With the device connected, modprobe usbnet module and configure usb0 interface (as root):
+
在连接上了装置之后,modprobe usbnet 模块及设定 usb0 接口 (以root身份):
 
<pre>
 
<pre>
 
ifconfig usb0 192.168.0.200 netmask 255.255.255.0
 
ifconfig usb0 192.168.0.200 netmask 255.255.255.0
 
</pre>
 
</pre>
If your eth0 interface is also in the same 'range' (e.g. 192.168.0.105) then you can do the following:
+
如果你的 eth0 接口位于同一个 '范围' (e.g. 192.168.0.105) 则你可以进行下面的工作:
  
1. ping the Neo with
+
1. 以下列指令ping Neo装置
 
  # ping -I usb0 192.168.0.202
 
  # ping -I usb0 192.168.0.202
2. add a route to your Neo:
+
2. 为Neo加入route:
 
  # /sbin/route add -host 192.168.0.202/32 dev usb0
 
  # /sbin/route add -host 192.168.0.202/32 dev usb0
3 log in to the Neo
+
3 登入 Neo
 
  # ssh root@192.168.0.202
 
  # ssh root@192.168.0.202
  
If you don't have the necessary modules to get usb0 going, make sure you have the following kernel options enabled:
+
若你没有必要的模块可以让usb0 运作,请确定你启用了以下的kernel选项:
 
* CONFIG_USB_USBNET
 
* CONFIG_USB_USBNET
 
* CONFIG_USB_NET_CDCETHER
 
* CONFIG_USB_NET_CDCETHER
Both options are available in the Device Drivers -> USB support -> USB Network Adapters. For more info see the [http://www.linux-usb.org/usbnet/ usbnet driver homepage].
+
二个选项都可以启动 Device Drivers -> USB support -> USB Network Adapters. For more info see the [http://www.linux-usb.org/usbnet/ usbnet driver homepage].
  
== Automatic method ==
+
== 自动化方法 ==
  
Took from [http://blog.haerwu.biz/2007/03/22/hotpluging-usbnet/ Hotplugging usbnet] post by Marcin 'Hrw' Juszkiewicz.
+
[http://blog.haerwu.biz/2007/03/22/hotpluging-usbnet/ Hotplugging usbnet] 取得,由 Marcin 'Hrw' Juszkiewicz张贴。
  
'''For Debian or similar distros:'''
+
 
Edit /etc/network/interfaces file ():
+
=== Debian 或相似的系统 ===
 +
Edit /etc/network/interfaces:
 
<pre>
 
<pre>
 
allow-hotplug usb0
 
allow-hotplug usb0
Line 71: Line 80:
 
</pre>
 
</pre>
  
'''For Ubuntu (Tested with Feisty and Gutsy):'''
+
=== Ubuntu (由Feisty、Gutsy 与Hardy测试) ===
Edit /etc/network/interfaces file ():
+
Edit /etc/network/interfaces:
 
<pre>
 
<pre>
 
auto usb0
 
auto usb0
Line 85: Line 94:
 
</pre>
 
</pre>
  
If you are doing the echo 1 > /proc/... command manually, sudo may not be enough, then you will have to execute it from a sudo bash.
+
若你执行用手动的方式执行 echo 1 > /proc/... 指令,sudo 可能尚嫌不足,接着,你则可以自auso bash执行。
 +
 
 +
Ubuntu Feisty、Gutsy 及 Hardy 在未挂载时,ifdown 是有臭虫的,也就是说,它只有在系统加载时可以执行。
 +
 
 +
这个臭虫很久之前已回报给ubuntu。因此,不要将这个臭虫夹文件,请在下列位置写入备忘:https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/130437
  
Ubuntu Feisty and Gutsy appear to have a bug where ifdown is not run when the interface is unplugged, meaning this only works once after the system is booted.
 
 
One can patch /etc/udev/rules.d/85-ifupdown.rules, editing the two lines at the end of the file:
 
One can patch /etc/udev/rules.d/85-ifupdown.rules, editing the two lines at the end of the file:
 
<pre>
 
<pre>
Line 104: Line 116:
 
</pre>
 
</pre>
  
the bug is that the LABEL="net_end" is at the wrong position
+
臭虫内容为LABEL="net_end" ,它被放在错的地方。
  
'''For Red Hat or similar distros'''
+
=== SuSE ===
Edit /etc/sysconfig/network-scripts/net.hotplug:
+
/etc/sysconfig/network/ifcfg-usb0
 +
# USB configuration for PDAs (openmoko)
 +
IPADDR=192.168.0.200
 +
NETMASK=255.255.255.0
 +
STARTMODE=onboot
 +
=== Fedora (由FC8测试) ===
 +
/etc/sysconfig/network-scripts/ifcfg-usb0
 +
<pre>
 +
# USB configuration for PDAs (openmoko)
 +
# from http://www.handhelds.org/moin/moin.cgi/UsbNet
 +
DEVICE=usb0
 +
BOOTPROTO=none
 +
IPADDR=192.168.0.200
 +
NETMASK=255.255.255.0
 +
ONBOOT=yes
 +
</pre>
  
After this statement:
+
=== Red Hat 或类似套件(在 Workstation 5下测试) ===
 +
编辑Edit /etc/sysconfig/network-scripts/net.hotplug:
 +
 
 +
在这个指令之后
 
<pre>
 
<pre>
 
     case $INTERFACE in
 
     case $INTERFACE in
 
# interfaces that are registered after being "up" (?)
 
# interfaces that are registered after being "up" (?)
 
</pre>
 
</pre>
 
+
加入
Add the following:
+
 
<pre>
 
<pre>
 
usb0)
 
usb0)
Line 128: Line 157:
 
</pre>
 
</pre>
  
'''For Gentoo or similar distros:'''
+
=== Gentoo ===
 +
* 开启 /etc/conf.d/net 并且加入add:
 +
# Neo1973
 +
config_usb0=( "192.168.0.200 netmask 255.255.255.0" )
 +
routes_usb0=( "192.168.0.202/32 via 192.168.0.200" )
 +
* 建立一个新的init script:
 +
cd /etc/init.d
 +
ln -s net.lo net.usb0
 +
* 将iptables放入使用:
 +
iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
 +
iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
 +
iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
 +
* 将它们存放在
 +
/etc/init.d/iptables save
 +
* I如果你希望在预设的情况下绕送:
 +
rc-update add iptables default
 +
* 你必须也通知 kernel,开始传送。建立以下的内容,则可以自动传送:
 +
create /etc/conf.d/net.usb0 as follows
 +
 +
preup() {
 +
        echo 1 > /proc/sys/net/ipv4/ip_forward
 +
        return 0
 +
}
 +
 +
postdown() {
 +
        echo 0 > /proc/sys/net/ipv4/ip_forward
 +
        return 0
 +
}
  
* Edit /etc/conf.d/net by adding:
+
用这个方法,封包传递将会在NEO连接上的时候开始传送,若关闭,则无法传送。
<pre>
+
  # Neo1973
+
  config_usb0=( "192.168.0.200 netmask 255.255.255.0" )
+
  routes_usb0=( "192.168.0.202/32 via 192.168.0.200" )
+
</pre>
+
* Create a new init script:
+
<pre>
+
  # cd /etc/init.d
+
  # ln -s net.lo net.usb0
+
</pre>
+
  
* Put iptables into use:
+
=== MacOS X ===
<pre>
+
请参考MacOS X[[MacOS_X#USB_Networking|USB Networking 一节]].
  # iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
+
  # iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
+
  # iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
+
</pre>
+
* Store them
+
<pre>
+
  # /etc/init.d/iptables save
+
</pre>
+
* If you want the routing to be switched on by default:
+
<pre>
+
  # rc-update add iptables default
+
</pre>
+
And now when you connect phone (which has 192.168.0.202 IP) it gets connection to world automatically.
+
  
'''For MacOS X:'''
+
= Mobile开发=
  
there are no files to edit since hotplugging configuration is done automatically by default. Of course, the interface has been initialized once. Install the AJZaurusUSB driver as described on [[MacOS_X]] and then open System Preferences / Networks which will show the new interface. Configure for Manual DHC with Host address 192.168.0.200 and Gateway 192.168.0.202.
+
== 代管DNS请求==
  
= Mobile development  =
+
若你是像我一样,常常搬家,必须透过DHCP连接到不同的网络,你可能会因为经常性的更新Neo 1973的resolv.conft而感到烦恼。
 
+
== Proxying DNS requests ==
+
 
+
If, like me, you move about quite a lot, connecting to various networks as you go and getting your ip via dhcp, you'll probably be annoyed at having to constantly update your resolv.conf on the Neo 1973.
+
 
+
To get round this, as part of my setup script, I run a proxy dns on the ip address the neo comes in on at the usb0 port. This means that my Neo /etc/resolv.conf only contains:
+
  
 +
要处理这个问题,如我的安装script,我在NEO USB0端口号的IP地址执行。这表示 Neo /etc/resolv.conf 只包含了:
 
  nameserver 192.168.0.200  
 
  nameserver 192.168.0.200  
  
and my laptop will proxy all dns requests based on it's own /etc/resolv.conf
+
我的计算机将只会依的 /etc/resolv.conf 代管DNS
 
+
'''note that we only run the dns proxy on the usb0 interface so that we don't break any other networking'''
+
  
=== Proxying with dnrd ===
+
'''请注意我们只会在usb0界面上执行dns proxy ,因此我们并不会破坏其它的网络联机'''
  
The script is designed to use [http://dnrd.sourceforge.net/ dnrd] as the dns proxy. The [http://buildhost.automated.it/gta01 script] and a copy of [http://buildhost.automated.it/dnrd-2.20.3.tar.gz dnrd] are available from my site. The script also performs the initial setup of the connection as per the [[USB_Networking#Manual_method]] above.
+
=== 使用 dnrd 代管===
  
=== Proxying with a UDP forwarder ===
+
这个 script 被设定为使用 [http://dnrd.sourceforge.net/ dnrd] 做为 dns proxy。[http://buildhost.automated.it/gta01 script] 及 [http://buildhost.automated.it/dnrd-2.20.3.tar.gz dnrd]的复本可以自我的网站取得。这个 script也可以执行上列的[[USB_Networking#Manual_method]]初始安装。
Another easy setup is using a udp forwarder like the one from http://www.tapor.com/udpf/ - is use it with the command
+
=== 以UDP forwarder代管 ===
 +
另一个简单的安装是使用来自http://www.tapor.com/udpf/ 的udp forwarder,它可以用下列指令操作:
  
 
  udpf-elf\
 
  udpf-elf\
Line 193: Line 220:
 
  iptables -t nat -A PREROUTING -p udp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1
 
  iptables -t nat -A PREROUTING -p udp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1
  
where <tt>192.168.0.1</tt> is the IP of your residential gateway (router). This is the easiest method, but its not recommended if you have a direct connection to the Internet as ISP DNS servers can change, and this does no load-balancing.
+
在这里<tt>192.168.0.1</tt> 是你的gateway的IP。它是最简单的方法,但是不建议这样做。但假设你有像ISP DNS服务一样直接连到网络,则建议这样做,但它无法做到流量调节。
  
= Connecting to phone =
+
= 连接到电话 =
  
Then <tt>ssh root@192.168.0.202</tt> with empty password to get into phone.
+
接着以空白密码连接到 <tt>ssh root@192.168.0.202</tt> 电话。
 +
 
 +
注意: 在Openmoko上的ssh daemon (dropbear 0.49) 的程序在传现及离开客端状态有 bug。你会收到的离开状态为255。
  
NOTE: the ssh daemon (dropbear 0.49) on the OpenMoko appears to have a bug when sending the exit status back to the client. From time to time you receive an exit status of 255.
 
  
 
===SSH Extras===
 
===SSH Extras===
  
If you get fed up with typing root@192.168.0.202, on your PC edit /etc/hosts and add an entry for 'phone'
+
I如果你在PC上键入root@192.168.0.202,编辑 /etc/hosts 并加入一个输入'phone'
  
 
  192.168.0.202 phone
 
  192.168.0.202 phone
  
then edit ~/.ssh/config (or create it) and add
+
接着编辑 edit ~/.ssh/config (或建立它) 并加入
  
 
  host phone
 
  host phone
 
  user root
 
  user root
  
then all you need to do is type
+
你必须做的工作是
  
 
  # ssh phone
 
  # ssh phone
  
To avoid ssh added a new line for every ssh host-key to you known_hosts you can add the following to the phone section in ~/.ssh/config
+
要避免 ssh 为每个已知的hostsssh host-key加入新的一行,你可以加下下列的内容到~/.ssh/config
  
 
   UserKnownHostsFile /dev/null
 
   UserKnownHostsFile /dev/null
  
You might want to use keys to bypass the login prompt too.
+
你可能想要使用 key 跳过这个过程。
  
 
===SSH Keys===
 
===SSH Keys===
====From host to phone====
+
====从主机到手机====
  
To generate ssh keys for use as a login mechanism type
+
要产生可以用的 ssh key 做为登入之用,请输入:
  
 
  ssh-keygen -t rsa
 
  ssh-keygen -t rsa
  
when prompted for a password either hit enter for no password (''not really a good idea'') or enter a password for this key. ssh into the phone and create ~/.ssh
+
在出现键入密码时,请键入ENTER(''虽然它不是个好主意'')或者是以这个KEY做为密码输入。ssh到手机,并且建立~/.ssh
  
 
  # mkdir ~/.ssh
 
  # mkdir ~/.ssh
  
then from your PC copy the '''.pub''' file to the phone.
+
接着,从你的计算机上复制 '''.pub'''档案到手机上
  
 
  # scp ~/.ssh/id_rsa.pub phone:.ssh/authorized_keys
 
  # scp ~/.ssh/id_rsa.pub phone:.ssh/authorized_keys
  
You should now be able to ssh directly into the phone.
+
你现在应该可以直接 ssh 到手机上
  
To disable password logins ('''after setting up key access''') edit /etc/init.d/dropbear and change the following line:
+
要停用登入密码 ('''在设定完KEY存取之后''') 编辑 /etc/init.d/dropbear 并且变更下列的内容
  
 
  DROPBEAR_EXTRA_ARGS=
 
  DROPBEAR_EXTRA_ARGS=
  
to
+
  
 
  DROPBEAR_EXTRA_ARGS="-s"
 
  DROPBEAR_EXTRA_ARGS="-s"
  
You will need to restart dropbear for this to take effect.
+
你必须重新启动,以让设定生效。
  
====From phone to host====
+
====从手机到主机====
Generate the key
+
产生key
  
 
   dropbearkey -t rsa -f id_rsa
 
   dropbearkey -t rsa -f id_rsa
  
The output will look something like this:
+
输出内容将如下:
  
 
   Will output 1024 bit rsa secret key to 'id_rsa'
 
   Will output 1024 bit rsa secret key to 'id_rsa'
Line 262: Line 290:
 
   Fingerprint: md5 ca:e8:f0:b7:f6:7b:c2:b6:b9:71:e4:45:86:a9:ff:b8
 
   Fingerprint: md5 ca:e8:f0:b7:f6:7b:c2:b6:b9:71:e4:45:86:a9:ff:b8
  
Copy and paste the one line (in this example, starting with 'ssh-rsa' onto the end of the host's authorized_keys file (often in ~/.ssh/).
+
复制并贴上以下的内容 (在这个范例当中,以'ssh-rsa' 开始,到主机的 authorized_keys 档案为止 (通常是在 ~/.ssh/).
  
From the phone, ssh with -i:
+
从手机,ssh  -i:
  
 
   ssh -i id_rsa user@host
 
   ssh -i id_rsa user@host
  
This works for me. I ripped off these instructions from: [[http://forum.openwrt.org/viewtopic.php?pid=53705]]
+
对我来讲,它是行的通的。 I ripped off these instructions from: [[http://forum.openwrt.org/viewtopic.php?pid=53705]]
  
===GUI on desktop through SSH===
+
[[Category:Hardware]]
 +
[[Category:USB| ]]
  
If you need to get the GUI on the phone onto the desktop via usb, you can use ssh as follows
+
===透过桌面的GUI SSH===
  
  ssh -l root -X -v 192.168.0.202
+
如果你必须方过USB取得手机上的GUI,你可以用下面的方式使用SSH:
  
Login, and run openmoko-finger-demo for example, and it will open up on the desktop. To get landscape view, just resize the GUI window on the desktop.
+
  ssh -l root -X -v 192.168.0.202
  
===Remote apps on neo===
+
如登入,并且执行openmoko-finger-demo ,它会在桌面开启。要取得横式的检视,请变更桌面的GUI窗口。
  
To get desktop apps to show up on your neo, first log in to the phone
+
===NEO上的远程程序===
  
 +
要让桌面上的程序能在你的NEO上显示,请登入手机:
 
   ssh -l root 192.168.0.202
 
   ssh -l root 192.168.0.202
  
Then once inside, run:
+
执行:
  
 
   DISPLAY=:0 xhost +192.168.0.200
 
   DISPLAY=:0 xhost +192.168.0.200
  
After this you can close the ssh session. Back on the desktop computer, run:
+
之后,你可以关闭ssh session。回到桌上型计算机,执行:
  
 
   DISPLAY=moko:0 xclock
 
   DISPLAY=moko:0 xclock
  
Note that the xhost command will allow remote applications on 192.168.0.200 to access the X server. It will allow anyone on the desktop machine to access the X server of the neo, including snooping anything you type on it. To disallow remote applications again, run this in the neo:
+
请注意xhost 指令只会允许远程应用程序在 192.168.0.200 存取X server。它允许任何人用桌上型机器存取neo X server。要停用远程应用程序,在NEO上执行:
  
 
   DISPLAY=:0 xhost -192.168.0.200
 
   DISPLAY=:0 xhost -192.168.0.200

Revision as of 13:04, 24 June 2008

Contents

Neo1973 side

命名方式

预设的状况下Neo1973拥有usb0界面,被编译到kernel中,做为以太网络装置。 在Neo上,如果你想要在网络上使用完整的主机名称,你必须定义你的DNS server。建立 /etc/resolv.conf档案,档案中要包含以下的内容:

nameserver xxx.xxx.xxx.xxx

e.g. nameserver 192.168.1.1

因此,你也可以轻松的使用 "ipkg update && ipkg upgrade" 更新 Neo.

更好的方法是编辑: /etc/network/interfaces 并且写入以下的内容:

up echo nameserver 192.168.0.200 >/etc/resolv.conf
要指定你喜好的DNS server而不是192.168.0.200。

example: up echo nameserver 4.2.2.2 >/etc/resolv.conf


另一个方法是symlink (NOW OBSOLETE?)

ln -s /var/run/resolv.conf /etc/resolv.conf

并且在启动 /etc/network/if-up.d/08setupdns script中写入:

#!/bin/sh -e
echo  nameserver 192.168.0.200 > /var/run/resolv.conf

使用这个方法可以在拨号到GPRS时,正确的从ppp 软件中处理。

Routing

你必须自额外的流量绕送到因特网上。 若你的计算机是预设的目的地位置,这个流量可以透过你的计算机被绕送出去 (see below)。你可以使用下列方法达到这个目地:

gateway 192.168.0.200

在usb0区段中到 /etc/network/interfaces。

Desktop side

手动

在连接上了装置之后,modprobe usbnet 模块及设定 usb0 接口 (以root身份):

ifconfig usb0 192.168.0.200 netmask 255.255.255.0

如果你的 eth0 接口位于同一个 '范围' (e.g. 192.168.0.105) 则你可以进行下面的工作:

1. 以下列指令ping Neo装置

# ping -I usb0 192.168.0.202

2. 为Neo加入route:

# /sbin/route add -host 192.168.0.202/32 dev usb0

3 登入 Neo

# ssh root@192.168.0.202

若你没有必要的模块可以让usb0 运作,请确定你启用了以下的kernel选项:

  • CONFIG_USB_USBNET
  • CONFIG_USB_NET_CDCETHER

二个选项都可以启动 Device Drivers -> USB support -> USB Network Adapters. For more info see the usbnet driver homepage.

自动化方法

Hotplugging usbnet 取得,由 Marcin 'Hrw' Juszkiewicz张贴。


Debian 或相似的系统

Edit /etc/network/interfaces:

allow-hotplug usb0
iface usb0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        post-up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -P FORWARD ACCEPT

Ubuntu (由Feisty、Gutsy 与Hardy测试)

Edit /etc/network/interfaces:

auto usb0
iface usb0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24 &
        up echo 1 > /proc/sys/net/ipv4/ip_forward &
        up iptables -P FORWARD ACCEPT &
        down iptables -D POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24 &

若你执行用手动的方式执行 echo 1 > /proc/... 指令,sudo 可能尚嫌不足,接着,你则可以自auso bash执行。

Ubuntu Feisty、Gutsy 及 Hardy 在未挂载时,ifdown 是有臭虫的,也就是说,它只有在系统加载时可以执行。

这个臭虫很久之前已回报给ubuntu。因此,不要将这个臭虫夹文件,请在下列位置写入备忘:https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/130437

One can patch /etc/udev/rules.d/85-ifupdown.rules, editing the two lines at the end of the file:

SUBSYSTEM=="net", DRIVERS=="?*", GOTO="net_start"
GOTO="net_end"

LABEL="net_start"

# Bring devices up and down only if they're marked auto.
# Use start-stop-daemon so we don't wait on dhcp
ACTION=="add",          RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifup -- --allow auto $env{INTERFACE}"

LABEL="net_end"

ACTION=="remove",       RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifdown -- --allow auto $env{INTERFACE}"

臭虫内容为LABEL="net_end" ,它被放在错的地方。

SuSE

/etc/sysconfig/network/ifcfg-usb0

# USB configuration for PDAs (openmoko)
IPADDR=192.168.0.200
NETMASK=255.255.255.0
STARTMODE=onboot

Fedora (由FC8测试)

/etc/sysconfig/network-scripts/ifcfg-usb0

# USB configuration for PDAs (openmoko)
# from http://www.handhelds.org/moin/moin.cgi/UsbNet
DEVICE=usb0
BOOTPROTO=none
IPADDR=192.168.0.200
NETMASK=255.255.255.0
ONBOOT=yes

Red Hat 或类似套件(在 Workstation 5下测试)

编辑Edit /etc/sysconfig/network-scripts/net.hotplug:

在这个指令之后

    case $INTERFACE in
	# interfaces that are registered after being "up" (?)

加入

	usb0)
		ifconfig usb0 192.168.0.200 netmask 255.255.255.0
		route add 192.168.0.202 usb0
		iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
		iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
                iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
                echo 1 > /proc/sys/net/ipv4/ip_forward
		exit 0
	;;

Gentoo

  • 开启 /etc/conf.d/net 并且加入add:
# Neo1973
config_usb0=( "192.168.0.200 netmask 255.255.255.0" )
routes_usb0=( "192.168.0.202/32 via 192.168.0.200" )
  • 建立一个新的init script:
cd /etc/init.d
ln -s net.lo net.usb0
  • 将iptables放入使用:
iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
  • 将它们存放在
/etc/init.d/iptables save
  • I如果你希望在预设的情况下绕送:
rc-update add iptables default
  • 你必须也通知 kernel,开始传送。建立以下的内容,则可以自动传送:
create /etc/conf.d/net.usb0 as follows

preup() {
       echo 1 > /proc/sys/net/ipv4/ip_forward
       return 0
}

postdown() {
       echo 0 > /proc/sys/net/ipv4/ip_forward
       return 0
}

用这个方法,封包传递将会在NEO连接上的时候开始传送,若关闭,则无法传送。

MacOS X

请参考MacOS XUSB Networking 一节.

Mobile开发

代管DNS请求

若你是像我一样,常常搬家,必须透过DHCP连接到不同的网络,你可能会因为经常性的更新Neo 1973的resolv.conft而感到烦恼。

要处理这个问题,如我的安装script,我在NEO USB0端口号的IP地址执行。这表示 Neo /etc/resolv.conf 只包含了:

nameserver 192.168.0.200 

我的计算机将只会依的 /etc/resolv.conf 代管DNS

请注意我们只会在usb0界面上执行dns proxy ,因此我们并不会破坏其它的网络联机

使用 dnrd 代管

这个 script 被设定为使用 dnrd 做为 dns proxy。scriptdnrd的复本可以自我的网站取得。这个 script也可以执行上列的USB_Networking#Manual_method初始安装。

以UDP forwarder代管

另一个简单的安装是使用来自http://www.tapor.com/udpf/ 的udp forwarder,它可以用下列指令操作:

udpf-elf\
       -p=53\
       -f=`cat /etc/resolv.conf|awk '$1 == "nameserver"{print $2; exit(0);}'`:53

Proxying with iptables

Its is possible to forward DNS requests with iptables using the DNAT target

iptables -t nat -A PREROUTING -p tcp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1
iptables -t nat -A PREROUTING -p udp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1

在这里192.168.0.1 是你的gateway的IP。它是最简单的方法,但是不建议这样做。但假设你有像ISP DNS服务一样直接连到网络,则建议这样做,但它无法做到流量调节。

连接到电话

接着以空白密码连接到 ssh root@192.168.0.202 电话。

注意: 在Openmoko上的ssh daemon (dropbear 0.49) 的程序在传现及离开客端状态有 bug。你会收到的离开状态为255。


SSH Extras

I如果你在PC上键入root@192.168.0.202,编辑 /etc/hosts 并加入一个输入'phone'

192.168.0.202 phone

接着编辑 edit ~/.ssh/config (或建立它) 并加入

host phone
user root

你必须做的工作是

# ssh phone

要避免 ssh 为每个已知的hostsssh host-key加入新的一行,你可以加下下列的内容到~/.ssh/config

 UserKnownHostsFile /dev/null

你可能想要使用 key 跳过这个过程。

SSH Keys

从主机到手机

要产生可以用的 ssh key 做为登入之用,请输入:

ssh-keygen -t rsa

在出现键入密码时,请键入ENTER(虽然它不是个好主意)或者是以这个KEY做为密码输入。ssh到手机,并且建立~/.ssh

# mkdir ~/.ssh

接着,从你的计算机上复制 .pub档案到手机上

# scp ~/.ssh/id_rsa.pub phone:.ssh/authorized_keys

你现在应该可以直接 ssh 到手机上

要停用登入密码 (在设定完KEY存取之后) 编辑 /etc/init.d/dropbear 并且变更下列的内容

DROPBEAR_EXTRA_ARGS=

DROPBEAR_EXTRA_ARGS="-s"

你必须重新启动,以让设定生效。

从手机到主机

产生key

 dropbearkey -t rsa -f id_rsa

输出内容将如下:

 Will output 1024 bit rsa secret key to 'id_rsa'
 Generating key, this may take a while...
 Public key portion is:
 ssh-rsa AAAAB3Nza[...]
 Fingerprint: md5 ca:e8:f0:b7:f6:7b:c2:b6:b9:71:e4:45:86:a9:ff:b8

复制并贴上以下的内容 (在这个范例当中,以'ssh-rsa' 开始,到主机的 authorized_keys 档案为止 (通常是在 ~/.ssh/).

从手机,ssh -i:

 ssh -i id_rsa user@host

对我来讲,它是行的通的。 I ripped off these instructions from: [[1]]

透过桌面的GUI SSH

如果你必须方过USB取得手机上的GUI,你可以用下面的方式使用SSH:

 ssh -l root -X -v 192.168.0.202

如登入,并且执行openmoko-finger-demo ,它会在桌面开启。要取得横式的检视,请变更桌面的GUI窗口。

NEO上的远程程序

要让桌面上的程序能在你的NEO上显示,请登入手机:

 ssh -l root 192.168.0.202

执行:

 DISPLAY=:0 xhost +192.168.0.200

之后,你可以关闭ssh session。回到桌上型计算机,执行:

 DISPLAY=moko:0 xclock

请注意xhost 指令只会允许远程应用程序在 192.168.0.200 存取X server。它允许任何人用桌上型机器存取neo X server。要停用远程应用程序,在NEO上执行:

 DISPLAY=:0 xhost -192.168.0.200

Personal tools

Neo1973 side

Name resolution

By default Neo1973 has usb0 interface working due to Ethernet gadget (g_ether) compiled into kernel.

On the Neo, if you want to reach out to the internets using full qualified hostnames, you need to define your DNS server. Create a file /etc/resolv.conf with at least one line saying

nameserver xxx.xxx.xxx.xxx

e.g. nameserver 192.168.1.1

Then you can also easily update your 2007.2 OpenMoko packages with "ipkg update && ipkg upgrade" on the Neo.

A better approach is to symlink

ln -s /var/run/resolv.conf /etc/resolv.conf

and fill the file at bootup with a script /etc/network/if-up.d/08setupdns containing:

#!/bin/sh -e
echo  nameserver 192.168.0.200 > /var/run/resolv.conf

this way the file is correctly handled from ppp package when dialing into gprs.

Routing

You need a additional route for traffic to the internet. This traffic can be routed through your pc (see below) if the pc is the default route destination. you can achieve this by adding

gateway 10.10.10.21

to your /etc/network/interfaces in the usb0 section.

Desktop side

Manual method

With the device connected, modprobe usbnet module and configure usb0 interface (as root):

ifconfig usb0 192.168.0.200 netmask 255.255.255.0

If your eth0 interface is also in the same 'range' (e.g. 192.168.0.105) then you can do the following:

1. ping the Neo with

# ping -I usb0 192.168.0.202

2. add a route to your Neo:

# /sbin/route add -host 192.168.0.202/32 dev usb0

3 log in to the Neo

# ssh root@192.168.0.202

If you don't have the necessary modules to get usb0 going, make sure you have the following kernel options enabled:

  • CONFIG_USB_USBNET
  • CONFIG_USB_NET_CDCETHER

Both options are available in the Device Drivers -> USB support -> USB Network Adapters. For more info see the usbnet driver homepage.

Automatic method

Took from Hotplugging usbnet post by Marcin 'Hrw' Juszkiewicz.

For Debian or similar distros: Edit /etc/network/interfaces file ():

allow-hotplug usb0
iface usb0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        post-up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -P FORWARD ACCEPT

For Ubuntu (Tested with Feisty and Gutsy): Edit /etc/network/interfaces file ():

auto usb0
iface usb0 inet static
        address 192.168.0.200
        netmask 255.255.255.0
        network 192.168.0.0
        up iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24 &
        up echo 1 > /proc/sys/net/ipv4/ip_forward &
        up iptables -P FORWARD ACCEPT &
        down iptables -D POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24 &

If you are doing the echo 1 > /proc/... command manually, sudo may not be enough, then you will have to execute it from a sudo bash.

Ubuntu Feisty and Gutsy appear to have a bug where ifdown is not run when the interface is unplugged, meaning this only works once after the system is booted. One can patch /etc/udev/rules.d/85-ifupdown.rules, editing the two lines at the end of the file:

SUBSYSTEM=="net", DRIVERS=="?*", GOTO="net_start"
GOTO="net_end"

LABEL="net_start"

# Bring devices up and down only if they're marked auto.
# Use start-stop-daemon so we don't wait on dhcp
ACTION=="add",          RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifup -- --allow auto $env{INTERFACE}"

LABEL="net_end"

ACTION=="remove",       RUN+="/sbin/start-stop-daemon --start --background --pidfile /var/run/network/bogus --startas /sbin/ifdown -- --allow auto $env{INTERFACE}"

the bug is that the LABEL="net_end" is at the wrong position

For Red Hat or similar distros Edit /etc/sysconfig/network-scripts/net.hotplug:

After this statement:

    case $INTERFACE in
	# interfaces that are registered after being "up" (?)

Add the following:

	usb0)
		ifconfig usb0 192.168.0.200 netmask 255.255.255.0
		route add 192.168.0.202 usb0
		iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
		iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
                iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
                echo 1 > /proc/sys/net/ipv4/ip_forward
		exit 0
	;;

For Gentoo or similar distros:

  • Edit /etc/conf.d/net by adding:
   # Neo1973
   config_usb0=( "192.168.0.200 netmask 255.255.255.0" )
   routes_usb0=( "192.168.0.202/32 via 192.168.0.200" )
  • Create a new init script:
   # cd /etc/init.d
   # ln -s net.lo net.usb0
  • Put iptables into use:
   # iptables -I INPUT 1 -s 192.168.0.202 -j ACCEPT
   # iptables -I OUTPUT 1 -s 192.168.0.200 -j ACCEPT
   # iptables -A POSTROUTING -t nat -j MASQUERADE -s 192.168.0.0/24
  • Store them
  # /etc/init.d/iptables save
  • If you want the routing to be switched on by default:
  # rc-update add iptables default

And now when you connect phone (which has 192.168.0.202 IP) it gets connection to world automatically.

For MacOS X:

there are no files to edit since hotplugging configuration is done automatically by default. Of course, the interface has been initialized once. Install the AJZaurusUSB driver as described on MacOS_X and then open System Preferences / Networks which will show the new interface. Configure for Manual DHC with Host address 192.168.0.200 and Gateway 192.168.0.202.

Mobile development

Proxying DNS requests

If, like me, you move about quite a lot, connecting to various networks as you go and getting your ip via dhcp, you'll probably be annoyed at having to constantly update your resolv.conf on the Neo 1973.

To get round this, as part of my setup script, I run a proxy dns on the ip address the neo comes in on at the usb0 port. This means that my Neo /etc/resolv.conf only contains:

nameserver 192.168.0.200 

and my laptop will proxy all dns requests based on it's own /etc/resolv.conf

note that we only run the dns proxy on the usb0 interface so that we don't break any other networking

Proxying with dnrd

The script is designed to use dnrd as the dns proxy. The script and a copy of dnrd are available from my site. The script also performs the initial setup of the connection as per the USB_Networking#Manual_method above.

Proxying with a UDP forwarder

Another easy setup is using a udp forwarder like the one from http://www.tapor.com/udpf/ - is use it with the command

udpf-elf\
       -p=53\
       -f=`cat /etc/resolv.conf|awk '$1 == "nameserver"{print $2; exit(0);}'`:53

Proxying with iptables

Its is possible to forward DNS requests with iptables using the DNAT target

iptables -t nat -A PREROUTING -p tcp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1
iptables -t nat -A PREROUTING -p udp -s 192.168.0.202 -d 192.168.0.200 --dport domain -j DNAT --to-destination 192.168.0.1

where 192.168.0.1 is the IP of your residential gateway (router). This is the easiest method, but its not recommended if you have a direct connection to the Internet as ISP DNS servers can change, and this does no load-balancing.

Connecting to phone

Then ssh root@192.168.0.202 with empty password to get into phone.

NOTE: the ssh daemon (dropbear 0.49) on the OpenMoko appears to have a bug when sending the exit status back to the client. From time to time you receive an exit status of 255.

SSH Extras

If you get fed up with typing root@192.168.0.202, on your PC edit /etc/hosts and add an entry for 'phone'

192.168.0.202 phone

then edit ~/.ssh/config (or create it) and add

host phone
user root

then all you need to do is type

# ssh phone

To avoid ssh added a new line for every ssh host-key to you known_hosts you can add the following to the phone section in ~/.ssh/config

 UserKnownHostsFile /dev/null

You might want to use keys to bypass the login prompt too.

SSH Keys

From host to phone

To generate ssh keys for use as a login mechanism type

ssh-keygen -t rsa

when prompted for a password either hit enter for no password (not really a good idea) or enter a password for this key. ssh into the phone and create ~/.ssh

# mkdir ~/.ssh

then from your PC copy the .pub file to the phone.

# scp ~/.ssh/id_rsa.pub phone:.ssh/authorized_keys

You should now be able to ssh directly into the phone.

To disable password logins (after setting up key access) edit /etc/init.d/dropbear and change the following line:

DROPBEAR_EXTRA_ARGS=

to

DROPBEAR_EXTRA_ARGS="-s"

You will need to restart dropbear for this to take effect.

From phone to host

Generate the key

 dropbearkey -t rsa -f id_rsa

The output will look something like this:

 Will output 1024 bit rsa secret key to 'id_rsa'
 Generating key, this may take a while...
 Public key portion is:
 ssh-rsa AAAAB3Nza[...]
 Fingerprint: md5 ca:e8:f0:b7:f6:7b:c2:b6:b9:71:e4:45:86:a9:ff:b8

Copy and paste the one line (in this example, starting with 'ssh-rsa' onto the end of the host's authorized_keys file (often in ~/.ssh/).

From the phone, ssh with -i:

 ssh -i id_rsa user@host

This works for me. I ripped off these instructions from: [[1]]

GUI on desktop through SSH

If you need to get the GUI on the phone onto the desktop via usb, you can use ssh as follows

 ssh -l root -X -v 192.168.0.202

Login, and run openmoko-finger-demo for example, and it will open up on the desktop. To get landscape view, just resize the GUI window on the desktop.

Remote apps on neo

To get desktop apps to show up on your neo, first log in to the phone

 ssh -l root 192.168.0.202

Then once inside, run:

 DISPLAY=:0 xhost +192.168.0.200

After this you can close the ssh session. Back on the desktop computer, run:

 DISPLAY=moko:0 xclock

Note that the xhost command will allow remote applications on 192.168.0.200 to access the X server. It will allow anyone on the desktop machine to access the X server of the neo, including snooping anything you type on it. To disallow remote applications again, run this in the neo:

 DISPLAY=:0 xhost -192.168.0.200