2.0 ubuntu系統固定ip

由於我的臺式機連接的路由器,這樣ip是隨機分配的。需要固定ip纔可以遠程方便連接。
若提示未找到 ifconfig 命令則使用如下命令按裝該工具。

bobokaka@bobokaka-desktop:~/桌面$ ifconfig
Command 'ifconfig' not found, but can be installed with:
sudo apt install net-tools
bobokaka@bobokaka-desktop:~/桌面$ 

安裝該工具。

sudo apt-get install net-tools

查看網卡。

bobokaka@bobokaka-desktop:~/桌面$ ifconfig
enp5s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.16  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::9585:63e5:3c44:4fe2  prefixlen 64  scopeid 0x20<link>
        ether 22:22:6c:08:00:c6  txqueuelen 1000  (以太網)
        RX packets 11301  bytes 8141556 (8.1 MB)
        RX errors 0  dropped 7  overruns 0  frame 0
        TX packets 9378  bytes 1471092 (1.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp6s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 22:22:6c:08:00:c7  txqueuelen 1000  (以太網)
        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  (本地環回)
        RX packets 1674  bytes 202716 (202.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1674  bytes 202716 (202.7 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

bobokaka@bobokaka-desktop:~/桌面$ 

可以看到我的網卡信息在enp5s0上面。
安裝vim。

sudo apt-get install vim

修改網卡默認配置文件。
原有配置如下:

 Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager

改成:

network:
  ethernets:
    enp5s0:
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.3.117/24
      routes:
        - to: default
          via: 192.168.3.1
      nameservers:
        addresses:
          - 192.168.3.1
          - 8.8.8.8
          - 114.114.114.114
  version: 2 
  renderer: networkd

當然,這裏只是參考。
其中

enp5s0是網卡名字
192.168.3.117是ip4的ip地質
子網掩碼是via。
DNS是addresses。

應用該配置。

sudo netplan apply
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章