系统相关
首页 > 系统相关> > ubuntu 20.04中配置静态IP

ubuntu 20.04中配置静态IP

作者:互联网

 

1、系统

root@liujiaxinpc1:/home/test# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.4 LTS
Release:        20.04
Codename:       focal

 

2、查看网卡名称

root@liujiaxinpc1:/home/test# netstat -i
Kernel Interface table
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens32     1500    48091      0      0 0          8458      0      0      0 BMRU
lo       65536      224      0      0 0           224      0      0      0 LRU

 

3、修改网络配置文件,保存退出

# This is the network config written by 'subiquity'??? 这个格式贼难调, 可以直接复制这个模板
network:
 ethernets:
  ens32:                       ## 网卡名称
   addresses:
   - 192.168.3.50/24           ## ip地址
   gateway4: 192.168.3.1       ## 网关
   nameservers:
    addresses:
    - 119.29.29.29             ## DNS服务
 version: 2

 

 

4、将网络模式调整为桥接模式

 

 

 

 

5、重启网络服务(如果出现报错,一般是网络配置文件格式的问题)

root@liujiaxinpc1:~/Desktop# netplan apply

 

6、查看ip

root@liujiaxinpc1:~/Desktop# ifconfig | head
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.50  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::1a8b:1520:347d:bea9  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ed:73:9d  txqueuelen 1000  (Ethernet)
        RX packets 49372  bytes 68621721 (68.6 MB)
        RX errors 0  dropped 239  overruns 0  frame 0
        TX packets 8854  bytes 653029 (653.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

 

7、测试网络

root@liujiaxinpc1:~/Desktop# ping -c 5 www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=51 time=17.8 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=51 time=18.2 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=51 time=17.7 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=51 time=17.8 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=51 time=18.0 ms

--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 17.713/17.907/18.166/0.164 ms

 

8、重启观察IP是否发生变化

root@liujiaxinpc1:~/Desktop# reboot

 

9、查看ip,检查网络连接

root@liujiaxinpc1:~/Desktop# ifconfig | head -n 5
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.3.50  netmask 255.255.255.0  broadcast 192.168.3.255
        inet6 fe80::20c:29ff:feed:739d  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ed:73:9d  txqueuelen 1000  (Ethernet)
        RX packets 40  bytes 2791 (2.7 KB)
root@liujiaxinpc1:~/Desktop# ping -c 5 www.baidu.com
PING www.a.shifen.com (39.156.66.18) 56(84) bytes of data.
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=1 ttl=51 time=17.8 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=2 ttl=51 time=17.8 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=3 ttl=51 time=17.9 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=4 ttl=51 time=17.7 ms
64 bytes from 39.156.66.18 (39.156.66.18): icmp_seq=5 ttl=51 time=17.8 ms

--- www.a.shifen.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4009ms
rtt min/avg/max/mdev = 17.718/17.804/17.893/0.055 ms

没有问题。

 

标签:66.18,IP,time,bytes,64,ms,ubuntu,39.156,20.04
来源: https://www.cnblogs.com/liujiaxin2018/p/16214940.html