# Ububntu 设置静态IP地址

在Ubuntu上设置静态IP地址需要编辑网络配置文件。以下是在Ubuntu 20.04上设置静态IP地址的步骤:

# 查看网络接口名称

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 04:7c:16:bc:2b:dd brd ff:ff:ff:ff:ff:ff
    inet 10.200.120.17/21 brd 10.200.127.255 scope global enp4s0
       valid_lft forever preferred_lft forever
    inet6 fe80::67c:16ff:febc:2bdd/64 scope link 
       valid_lft forever preferred_lft forever
3: wlo1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 0c:91:92:05:a1:ef brd ff:ff:ff:ff:ff:ff
    altname wlp0s20f3
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
    link/ether 02:42:df:45:a7:c4 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
       valid_lft forever preferred_lft forever

# 编辑网络配置文件

$ sudo vim /etc/netplan/00-installer-config.yaml 

# 新增如下配置信息

# This is the network config written by 'subiquity'
network:
  ethernets:
    enp4s0:
      # dhcp4: true
      addresses: [10.200.120.17/21]
      routes:
        - to: default
          via: 10.200.124.254
      nameservers:
        addresses: [192.168.0.170, 192.168.100.200]
  version: 2

# 应用配置

$ sudo netplan apply