記錄一下配置服務(wù)器過(guò)程,本以為簡(jiǎn)單,結(jié)果整了一天。
服務(wù)器有2個(gè)網(wǎng)口,網(wǎng)口2是用來(lái)上外網(wǎng)的,原來(lái)用的01-netcfg.yaml進(jìn)行ip地址設(shè)置,主要就用2條命令:
vi /etc/netplan/01-netcfg.yaml (打開(kāi)后進(jìn)行修改)
netplan apply??(應(yīng)用配置,不正確會(huì)報(bào)錯(cuò))
起初,配置的01-netcfg.yaml內(nèi)容:
# 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是外網(wǎng)網(wǎng)口,打死都ping www.baidu.com都不通的。但ping外網(wǎng)的網(wǎng)關(guān)192.168.110.1是通的。
后來(lái)想起是不是默認(rèn)就是用第1個(gè)網(wǎng)口去連外網(wǎng)的?用route -n一看,果然是。網(wǎng)上也沒(méi)告訴方法把第2口設(shè)置成默認(rèn)的網(wǎng)關(guān),那就把第1口的網(wǎng)關(guān)和域名服務(wù)器刪了,就應(yīng)該是第2口作為默認(rèn)網(wǎng)關(guān)了吧?!
新配置如下:
# 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;但是服務(wù)器依舊ping不通,route -n依舊不變的,那可能需要重啟?!reboot,漫長(zhǎng)等待后,route -n果然變成192.168.110.1作為網(wǎng)關(guān)排到前面的了。ping www.baidu.com就通的了。
正確的狀態(tài):
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 域名服務(wù)器地址
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 百度文章來(lái)源:http://www.zghlxwxcb.cn/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文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-792517.html
到了這里,關(guān)于ubuntu18.04服務(wù)器雙網(wǎng)口配置上外網(wǎng)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!