1. The iptable command used :
clear firewall rules
iptables -F
iptables -F -t nat
Query firewall rules
iptables -L
iptables -L -t nat
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o eth5 -j MASQUERADE
2. Build in Ubuntu environment
First turn on two network cards (bridge), one connected to the computer's wired network ( eth2 ), and one connected to the computer's wireless network card ( eth5 ). Use eth2 as the lan port and eth5 as the wan port.
Set the eth2 ip 192.168.4.1 routing address and remove the gateway.
Set eth5 ip --- can connect to external network ip address, add gateway such as:
route add default gw 192.168.1.1 dev eth5
Set forwarding command
#echo 1 >> /proc/sys/net/ipv4/ip_forward
set iptable command
iptables -F
iptables -F -t nat
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o eth5 -j MASQUERADE
In this way, connect the wired port of the computer to the switch port, and other machines connected to the switch can access the Internet.
3. Android machine
使用4G网卡ppp0作为wan口,有线eth0作为lan口,eth0设置ip为
busybox ifconfig eth0 192.168.4.1 不要设置网关。
4G网关和ip自动设置。
设置转发命令
#echo 1 >> /proc/sys/net/ipv4/ip_forward
设置iptable命令
iptables -F -t nat ;iptables -F; iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
5.连接路由的客户端网络参数获取:
静态IP设置模式
虚拟机设置一个ip如:桥接到有线网卡中,与安卓机器eth0用同一个交换机
ifconfig eth5 192.168.4.102 ;route del default; route add default gw 192.168.4.1 dev eth5
同时虚拟机也需要设置一下DNS,用getprop命令查看安卓系统dns,然后将该DNS设置到虚拟机中(Ubuntu)。
动态IP设置模式
Dhcp服务器
使用busybox本身的dhcp功能,从busybox-1.16.1\examples\udhcp 目录中获取到
udhcpd.conf修改内容:
start 192.168.4.20
end 192.168.4.254
opt dns 210.21.4.130 221.5.88.88
option subnet 255.255.255.0
opt router 192.168.4.1
#opt wins 192.168.10.10
#option dns 129.219.13.81 # appened to above DNS servers for a total of 3
option domain local
option lease 864000 # 10 days of seconds
放入安卓系统中(/etc),执行启动服务器命令:
busybox udhcpd -fS /etc/udhcpd.conf &
对于iptable的详细介绍请点击点击打开链接