ubuntu server18.04配置网络
Posted pocean2012
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu server18.04配置网络相关的知识,希望对你有一定的参考价值。
新安装的服务器,系统安装的ubuntu server18.04, 想当然以为网线插上就能正常连接,谁知不是这么回事。
查阅资料,参考文章
https://www.cnblogs.com/jianxuanbing/archive/2018/11/30/10042892.html
依葫芦画瓢,多次尝试,发现中间vim编辑的小trick,原文未说明。
1. 查看确认网卡信息
(base) xxxxx@jxxx:~$ ifconfig -a
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.105 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::862b:2bff:fe2b:1fde prefixlen 64 scopeid 0x20<link>
ether 84:2b:2b:2b:1f:de txqueuelen 1000 (Ethernet)
RX packets 4701 bytes 668439 (668.4 KB)
RX errors 0 dropped 492 overruns 0 frame 0
TX packets 2200 bytes 325065 (325.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno2: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 84:2b:2b:2b:1f:e0 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno3: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 84:2b:2b:2b:1f:e2 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno4: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 84:2b:2b:2b:1f:e4 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 14804 bytes 1098636 (1.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14804 bytes 1098636 (1.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2. 调用netplan生成文件并编辑配置文件
sudo netplan generate
sudo vim /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
eno1:
addresses:
- 192.168.0.105/24
dhcp4: false
gateway4: 192.168.0.1
nameservers:
addresses:
- 8.8.8.8
eno1:
dhcp4: yes
以上将网卡1 设为固定ip, 网卡2设为自动获取
这里注意,缩进全部用空格,不能用tab,否则会报错
3. 运行netplan生效
(base) xxx@jsxxe:~$ sudo netplan apply
(base) xxxx@xxxx:~$ ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.105 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::862b:2bff:fe2b:1fde prefixlen 64 scopeid 0x20<link>
ether 84:2b:2b:2b:1f:de txqueuelen 1000 (Ethernet)
RX packets 5618 bytes 784304 (784.3 KB)
RX errors 0 dropped 565 overruns 0 frame 0
TX packets 2670 bytes 415017 (415.0 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 14804 bytes 1098636 (1.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 14804 bytes 1098636 (1.0 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
搞定
以上是关于ubuntu server18.04配置网络的主要内容,如果未能解决你的问题,请参考以下文章
VMware下Ubuntu 18.04Server设置静态IP图文教程