自学内容网 自学内容网

Ubuntu Server 24.04 配置静态IP

Ubuntu Server 24.04 配置静态IP

提示:基于Ubuntu Server 24.04进行配置



一、查看网卡信息

使用命令 ip a
lo 为本地回环地址
ens33 真实网卡地址

shanfeng@ubuntu:~$ ip a
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 noprefixroute 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:2e:eb:4b brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.10.3/24 brd 192.168.10.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe2e:eb4b/64 scope link 
       valid_lft forever preferred_lft forever

二、修改网卡信息

sudo vi /etc/netplan/50-cloud-init.yaml
注意:一定要加sudo 否则修改完成后 无法保存

network:
  ethernets:
    ens33: # 网卡名称
      addresses: [192.168.10.3/24]  # 要配置的静态IP地址   /24 代表子网掩码为 255.255.255.0
      gateway4: 192.168.10.2        # 网关地址  根据真实情况填写
      dhcp4: false# 是否启用dhcp  因为配置静态IP 所以这里是flase
      nameservers:# 配置dns 
        addresses: [223.5.5.5,114.114.114.114,8.8.8.8]
  version: 2
  renderer: networkd# 这行一定要加 不加报错

三、使网卡配置生效

shanfeng@ubuntu:~$ sudo netplan apply

四、测试

shanfeng@ubuntu:~$ ping www.baidu.com
PING www.a.shifen.com (110.242.68.4) 56(84) bytes of data.
64 bytes from 110.242.68.4: icmp_seq=1 ttl=128 time=33.9 ms
64 bytes from 110.242.68.4: icmp_seq=2 ttl=128 time=23.7 ms
64 bytes from 110.242.68.4: icmp_seq=3 ttl=128 time=24.2 ms
64 bytes from 110.242.68.4: icmp_seq=4 ttl=128 time=23.8 ms
64 bytes from 110.242.68.4: icmp_seq=5 ttl=128 time=30.3 ms
^C
--- www.a.shifen.com ping statistics ---
6 packets transmitted, 5 received, 16.6667% packet loss, time 5010ms
rtt min/avg/max/mdev = 23.721/27.190/33.905/4.180 ms

原文地址:https://blog.csdn.net/qq_18715339/article/details/145118976

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!