美文网首页
2.0 ubuntu系统固定ip

2.0 ubuntu系统固定ip

作者: bobokaka | 来源:发表于2022-11-20 00:13 被阅读0次

    由于我的台式机连接的路由器,这样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
    

    相关文章

      网友评论

          本文标题:2.0 ubuntu系统固定ip

          本文链接:https://www.haomeiwen.com/subject/pjkmxdtx.html