zoukankan      html  css  js  c++  java
  • Ubuntu 18.04 设置静态 ip 的方法

    查看网卡名

    $ ifconfig
    enp6s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            inet 192.168.1.20  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::ca5b:76ff:fe5d:8241  prefixlen 64  scopeid 0x20<link>
            ether c8:5b:76:5d:82:41  txqueuelen 1000  (Ethernet)
            RX packets 1139  bytes 159452 (159.4 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 1059  bytes 96481 (96.4 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0...

    方法1(需要重启才能生效)

    打开,

    $ sudo vim /etc/network/interfaces

    如下修改,重启生效(使用 $ sudo service networking restart 无效),

    # interfaces(5) file used by ifup(8) and ifdown(8)
    auto lo
    iface lo inet loopback
    
    #################################################### Add by User Start
    auto enp6s0
    iface enp6s0 inet static
    address 192.168.1.20
    netmask 255.255.255.0
    #getway 192.168.1.1     # 一般不用设置
    #################################################### Add by User End

    方法2(不需要重启)推荐

    打开,

    $ sudo vim /etc/netplan/01-network-manager-all.yaml    # 一般仅有一个 .yaml 文件

    原始内容为,

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

    修改为固定 ip 地址 ,

    # Let NetworkManager manage all devices on this system
    #network:
    #  version: 2
    #  renderer: NetworkManager
    #  ethernets:
    #      enp6s0:
    #          dhcp4: yes 
    
    network:
      version: 2
      ethernets:
          enp6s0:
              dhcp4: no
              addresses: [192.168.1.22/24]
              optional: true
              gateway4: 192.168.1.1
              nameservers:
                  addresses: [192.168.1.1]

    执行,

    $ sudo netplan apply 

     如果要还原更改为 DHCP,修改上述文件为,

    # Let NetworkManager manage all devices on this system
    network:
      version: 2
      renderer: NetworkManager
      ethernets:
          enp6s0:
              dhcp4: yes 
    
    #network:
    #  version: 2
    #  ethernets:
    #      enp6s0:
    #          dhcp4: no
    #          addresses: [192.168.1.22/24]
    #          optional: true
    #          gateway4: 192.168.1.1
    #          nameservers:
    #              addresses: [192.168.1.1]

    再次执行,

    $ sudo netplan apply

    CentOS 设置静态 ip,参见: https://www.cnblogs.com/gaowengang/p/13458591.html

    (完)

  • 相关阅读:
    3.22
    练习 3.16
    简单工厂模式
    Java-不可变字符串
    java中的缓冲流
    TCP协议下java通信
    nginx优化
    nginx反向代理
    shell-for循环
    shell-数组
  • 原文地址:https://www.cnblogs.com/gaowengang/p/12494267.html
Copyright © 2011-2022 走看看