momo zone

调核人的blog

linux 多网卡共享internet

 |-------|eth0 192.168.5.2               eth1 192.168.5.1|--------------|eth0 192.168.3.136                  |-----------------|eth1 192.168.1.2      192.168.1.1 |--------------------------|
 |host  |--------------------------------------------------------|host share |------------------------------------------|router ddwrt  |------------------------------------------|router internet home|
 |-------|                                                        |--------------|                      br0 192.168.3.1 |-----------------|                                          |--------------------------|

host share:

echo 1 >/proc/sys/net/ipv4/ip_forward

Dekernel:~ # route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.3.1 0.0.0.0 UG 0 0 0 eth0
127.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 lo
192.168.3.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
192.168.5.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

route ddwrt

route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.3.136

root@router:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.5.0 192.168.3.136 255.255.255.0 UG 0 0 0 br0
192.168.3.0 * 255.255.255.0 U 0 0 0 br0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth1
169.254.0.0 * 255.255.0.0 U 0 0 0 br0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth1

 

补充:

如果不想在route上添加路由也能共享,就需要host share从二层转发,其实就是NAT 功能 ,可以用iptables实现:

iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -t nat -A POSTROUTING -o eth_s0_0 -j MASQUERADE

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: