记录一下配置服务器过程,本以为简单,结果整了一天。
服务器有2个网口,网口2是用来上外网的,原来用的01-netcfg.yaml进行ip地址设置,主要就用2条命令:
vi /etc/netplan/01-netcfg.yaml (打开后进行修改)
netplan apply (应用配置,不正确会报错)
起初,配置的01-netcfg.yaml内容:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: no
dhcp6: no
addresses: [172.18.36.110/24]
gateway4: 172.18.36.1
nameservers:
addresses: [172.18.36.1]
eno2:
dhcp4: no
dhcp6: no
addresses: [192.168.110.110/24]
gateway4: 192.168.110.1
nameservers:
addresses: [192.168.110.1]
eno2是外网网口,打死都ping www.baidu.com都不通的。但ping外网的网关192.168.110.1是通的。
后来想起是不是默认就是用第1个网口去连外网的?用route -n一看,果然是。网上也没告诉方法把第2口设置成默认的网关,那就把第1口的网关和域名服务器删了,就应该是第2口作为默认网关了吧?!
新配置如下:
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eno1:
dhcp4: no
dhcp6: no
addresses: [172.18.36.110/24]
gateway4: 192.168.110.1
eno2:
dhcp4: no
dhcp6: no
addresses: [192.168.110.110/24]
gateway4: 192.168.110.1
nameservers:
addresses: [192.168.110.1]
之后,netplan apply;但是服务器依旧ping不通,route -n依旧不变的,那可能需要重启?!reboot,漫长等待后,route -n果然变成192.168.110.1作为网关排到前面的了。ping www.baidu.com就通的了。
正确的状态:
root@ubuntu:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.110.1 0.0.0.0 UG 0 0 0 eno2
0.0.0.0 172.18.36.1 0.0.0.0 UG 0 0 0 eno1
172.16.20.0 0.0.0.0 255.255.252.0 U 0 0 0 eno2
172.18.35.0 0.0.0.0 255.255.255.0 U 0 0 0 eno2
172.18.36.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1
192.168.110.0 0.0.0.0 255.255.255.0 U 0 0 0 eno2
//ping 域名服务器地址
root@ubuntu:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=108 time=186 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=108 time=185 ms
//ping 百度文章来源:https://www.toymoban.com/news/detail-792517.html
root@ubuntu:~# ping www.baidu.com
PING www.a.shifen.com (180.101.50.188) 56(84) bytes of data.
64 bytes from 180.101.50.188: icmp_seq=1 ttl=50 time=7.97 ms
64 bytes from 180.101.50.188: icmp_seq=2 ttl=50 time=7.70 ms
64 bytes from 180.101.50.188: icmp_seq=3 ttl=50 time=7.70 ms文章来源地址https://www.toymoban.com/news/detail-792517.html
到了这里,关于ubuntu18.04服务器双网口配置上外网的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!