ubuntu - linux服务器双网卡连接到路由器共享网络,应该如何配置NAT?
高洛峰
高洛峰 2017-04-21 10:55:29
0
2
540

服务器是ubuntu server 12.04 i386,装有双网卡。其中eth0连接到外网,eth1连接到路由器的WAN端口。想创建一个共享wifi,使其他设备都能通过服务器上网

cat /etc/network/interfaces

auto lo iface lo inet loopback #连接到外网 auto eth0 iface eth0 inet static address 212.114.20.78 netmask 255.255.255.0 gateway 212.114.20.126 dns-nameservers 212.114.0.242 8.8.8.8 #连接到路由器 auto eth1 iface eth1 inet static address 192.168.1.254 netmask 255.255.255.0

route -n

Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 212.114.20.126 0.0.0.0 UG 100 0 0 eth0 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1 212.114.20.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

路由器设置如下:

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all (2)
PHPzhong
echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE

Also, what is the routing table of your server (route -noutput).

    洪涛
    • Confirm that the physical wiring is correct, whether it canpingpassgatewayanddns, and whethereth1is connected to theWANport (non-LAN port)
    • Modify/etc/network/interfaces(corresponding to the changes to the eth0 part above)
    • Make the modification effective:sudo /etc/init.d/networking restart
    • Set the router as shown in the picture above and enable the routerDHCPservice
    • sudoExecute the following command:
    /sbin/iptables -F /sbin/iptables -X /sbin/iptables -Z /sbin/iptables -F -t nat /sbin/iptables -X -t nat /sbin/iptables -Z -t nat /sbin/iptables -P INPUT ACCEPT /sbin/iptables -P OUTPUT ACCEPT /sbin/iptables -P FORWARD ACCEPT /sbin/iptables -t nat -P PREROUTING ACCEPT /sbin/iptables -t nat -P POSTROUTING ACCEPT /sbin/iptables -t nat -P OUTPUT ACCEPT echo 1 > /proc/sys/net/ipv4/ip_forward iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
    • Addiptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADEto/etc/rc.local
    • If it still doesn’t work, check whether you followed Evian’s answers and comments
      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!