pi@raspberrypi:~$ sudo sh -c "iptables-save > /etc/network/iptables"
pi@raspberrypi:~$ cat /etc/network/iptables
# Generated by iptables-save v1.4.14 on Sun Jun 15 05:45:28 2014
*filter
:INPUT ACCEPT [22972:1979567]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2421:275063]
-A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth0 -o wlan0 -j ACCEPT
COMMIT
# Completed on Sun Jun 15 05:45:28 2014
# Generated by iptables-save v1.4.14 on Sun Jun 15 05:45:28 2014
*nat
:PREROUTING ACCEPT [9719:1105033]
:INPUT ACCEPT [1273:238753]
:OUTPUT ACCEPT [675:88515]
:POSTROUTING ACCEPT [219:34192]
-A POSTROUTING -o wlan0 -j MASQUERADE
COMMIT
# Completed on Sun Jun 15 05:45:28 2014
pi@raspberrypi:~$
在/etc/network/interfaces上加上一句up iptables-restore < /etc/network/iptables使得每次启动的时候自动生效
pi@raspberrypi:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet static
address 172.16.1.100
netmask 255.255.255.0
gateway 172.16.1.1
#########################################
allow-hotplug wlan0
iface wlan0 inet static
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
wireless-essid ADSL-WiFi-c91f44
wireless-key 1234567890
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.254
up iptables-restore < /etc/network/iptables
保存重启发现连上Raspberry Pi的RJ45口的便携机能自动获取IP地址,并且可以ping通外网了。