Ubuntu服務器雙網配置
內網:192.168.13.181
外網:10.72.66.249
-
進入網絡配置
sudo vim /etc/network/interfaces auto eno1 iface eno1 inet dhcp iface eno1 inet static address 192.168.13.181 netmask 255.255.255.0 gateway 192.168.13.80 auto eno2 iface eno2 inet static address 10.72.66.249 netmask 255.255.255.128 #gatway 10.72.66.xxx
-
添加DNS並使其生效
sudo vim /etc/resolvconf/resolv.conf.d/base nameserver 10.33.112.XX sudo resolvconf -u -- 使dns生效
-
重啓網卡
sudo /etc/init.d/networking restart
-
查看當前路由
Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.13.244 0.0.0.0 UG 0 0 0 eno1 10.72.66.128 0.0.0.0 255.255.255.128 U 0 0 0 eno2 192.168.13.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1 -- 無eno2網關
sudo route add default gw 10.72.66.xxx -- 再次查看 以添加 10.72.66.xxx Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.72.66.xxx 0.0.0.0 UG 0 0 0 eno2 0.0.0.0 192.168.13.244 0.0.0.0 UG 0 0 0 eno1 10.72.66.128 0.0.0.0 255.255.255.128 U 0 0 0 eno2 192.168.13.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1
-
測試是否成功
-- 外網 PING 11.71.15.xx (11.71.15.xx) 56(84) bytes of data. 64 bytes from 11.71.15.xx: icmp_seq=1 ttl=250 time=1.59 ms 64 bytes from 11.71.15.xx: icmp_seq=2 ttl=250 time=1.53 ms -- 內網 ping 192.168.13.xx PING 192.168.13.134 (192.168.13.xx) 56(84) bytes of data. 64 bytes from 192.168.13.xx: icmp_seq=1 ttl=128 time=0.786 ms 64 bytes from 192.168.13.1xx: icmp_seq=2 ttl=128 time=0.394 ms