查看网卡

1
ifconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
docker0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
ether 02:42:69:f0:8b:f5 txqueuelen 0 (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

ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.27 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::20c:29ff:fea0:c420 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:a0:c4:20 txqueuelen 1000 (Ethernet)
RX packets 10021 bytes 919655 (919.6 KB)
RX errors 0 dropped 5 overruns 0 frame 0
TX packets 7629 bytes 9885571 (9.8 MB)
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 427 bytes 502877 (502.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 427 bytes 502877 (502.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

编辑配置文件

1
2
cd /etc/netplan/
ls
1
00-installer-config.yaml
1
sudo vim 00-installer-config.yaml 
  • 这里选择要修改的网卡的配置文件

    配置示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # This is the network config written by 'subiquity'
    network:
    ethernets:
    ens160:
    dhcp4: false
    addresses:
    - 192.168.0.27/24
    routes:
    - to: default
    via: 192.168.0.1
    nameservers:
    addresses: [114.114.114.114,8.8.8.8]
    version: 2

    重启网络

    1
    sudo netplan apply