Ubuntu 18.04 固定IP设置(设备测试有效)

本文介绍了如何在Linux系统中查看网关信息,包括内核IP路由表和netplan工具的使用方法。讲解了如何修改netplan配置文件,备份并应用新的配置以确保网络连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看网关信息

	ak@mac:/etc/netplan$ route -n
	内核 IP 路由表
	目标            网关            子网掩码        标志  跃点   引用  使用 接口
	0.0.0.0         192.168.200.2   0.0.0.0         UG    20100  0        0 ens33
	169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 ens33
	192.168.200.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33

查看网关配置文件位置

	ak@mac:/etc/netplan$ netplan -h
	usage: /usr/sbin/netplan  [-h] [--debug]  ...
	
	Network configuration in YAML
	
	optional arguments:
	  -h, --help  show this help message and exit
	  --debug     Enable debug messages

	Available commands:
	  
	    help      Show this help message
	    apply     Apply current netplan config to running system
	    generate  Generate backend specific configuration files from
	              /etc/netplan/*.yaml
	    ip        Retrieve IP information from the system
	    try       Try to apply a new netplan config to running system, with
	              automatic rollback

修改文件(建议先备份)

	ak@mac:~$ cd /etc/netplan/
	ak@mac:/etc/netplan$ ls
	01-network-manager-all.yaml
	ak@mac:/etc/netplan$ sudo cp 01-network-manager-all.yaml 01-network-manager-all.yaml.back	//建议先备份
	ak@mac:/etc/netplan$ sudo vim 01-network-manager-all.yaml	//修改文件
	ak@mac:/etc/netplan$ cat 01-network-manager-all.yaml		//修改内容

应用配置,使其生效

	ak@mac:/etc/netplan$ sudo netplan apply

ping任意网址查看是否联网

	ak@mac:/etc/netplan$ ping www.baidu.com
	PING www.a.shifen.com (14.119.104.189) 56(84) bytes of data.
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=1 ttl=128 time=6.61 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=2 ttl=128 time=6.93 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=3 ttl=128 time=9.09 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=4 ttl=128 time=7.76 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=5 ttl=128 time=7.12 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=6 ttl=128 time=7.55 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=7 ttl=128 time=6.46 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=8 ttl=128 time=6.83 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=9 ttl=128 time=6.55 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=10 ttl=128 time=6.45 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=11 ttl=128 time=6.60 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=12 ttl=128 time=6.48 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=13 ttl=128 time=6.46 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=14 ttl=128 time=7.29 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=15 ttl=128 time=6.74 ms
	64 bytes from 14.119.104.189 (14.119.104.189): icmp_seq=16 ttl=128 time=6.85 ms
	^C
	--- www.a.shifen.com ping statistics ---
	16 packets transmitted, 16 received, 0% packet loss, time 15027ms
	rtt min/avg/max/mdev = 6.450/6.988/9.094/0.672 ms
	ak@mac:/etc/netplan$ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值