当前位置:首页>文章中心>行业新闻>ubuntu22.04中配置静态IP

ubuntu22.04中配置静态IP

发布时间:2013-06-26 点击数:126


001、进入该目录

root@utuntu01:~# cd /etc/netplan/    ## 进入该目录root@utuntu01:/etc/netplan# ls01-network-manager-all.yaml
root@utuntu01:/etc/netplan#

 

002、备份配置文件

复制代码    
root@utuntu01:/etc/netplan# ls01-network-manager-all.yaml
root@utuntu01:/etc/netplan# cp 01-network-manager-all.yaml 01-network-manager-all.yaml_bak       ## 备份配置文件root@utuntu01:/etc/netplan# ls01-network-manager-all.yaml  01-network-manager-all.yaml_bak
   
复制代码    

 

03、查看网卡名称

复制代码    
root@utuntu01:/etc/netplan# ifconfig | head        ## 查看网卡名称ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.74.128  netmask 255.255.255.0  broadcast 192.168.74.255
        inet6 fe80::d6ac:35f3:d011:3c5d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:e7:69:41  txqueuelen 1000  (Ethernet)
        RX packets 253976  bytes 362493476 (362.4 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 20024  bytes 1257307 (1.2 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
   
复制代码    

 

003、修改配置文件

root@utuntu01:/etc/netplan# ls01-network-manager-all.yaml  01-network-manager-all.yaml_bak
root@utuntu01:/etc/netplan# vim 01-network-manager-all.yaml    ## 修改为如下内容, 网卡:ens32, ip:192.168.74.129, 子网掩码:24, DNS:119.29.29.29,网关:192.168.74.2; 然后保存退出
复制代码    
# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens32:
      addresses:        - 192.168.74.129/24
      nameservers:
        addresses: [119.29.29.29, 8.8.8.8]
      routes:        - to: default
          via: 192.168.74.2
  version: 2
   
复制代码    

 

 

 

 

 

 

004、

root@utuntu01:/etc/netplan# netplan apply

 

005、验证配置效果

root@utuntu01:/etc/netplan# ip addr

 

006、验证网络

root@utuntu01:/etc/netplan# ping -c 3 www.baidu.com

 


微信二维码

15935144090