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
注 意 第 二 个 网 关 一 定 不 能 配 置 # g a t w a y 10.72.66. x x x \color{#FF3030}{注意第二个网关一定不能配置\#gatway 10.72.66.xxx} 注意第二个网关一定不能配置#gatway10.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网关
− − 手 动 添 加 e n o 2 网 段 网 关 \color{#FF3030}{-- 手动添加 eno2网段网关} −−手动添加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