centos7.5固定局域网ip
2018-09-29 17:47 丨o聽乄雨o丨 阅读(1344) 评论(0) 编辑 收藏 举报有de时候,比如像我们单位,没事干就停一次网,结果ip变了,还得重新看ip,重新配置,很麻烦,所以干脆把自己ip固定,以不变应万变!!!
1.首先查看自己的ip是什么:
$ ifconfig eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.13.196 netmask 255.255.255.0 broadcast 172.16.13.* inet6 fe80::f3ec:2efd:b99a:* prefixlen 64 scopeid 0x20<link> ether 4c:cc:6a:*:*:* txqueuelen 1000 (Ethernet) RX packets 3579688 bytes 1315908957 (1.2 GiB) RX errors 0 dropped 53 overruns 0 frame 0 TX packets 959049 bytes 160239316 (152.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 16 memory 0xdf100000-df120000 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 50192 bytes 17673476 (16.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 50192 bytes 17673476 (16.8 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:e7:f2:e5 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
发现有三个网卡设备,其中eno1是我们的有线网卡,ip地址是172.16.13.196,netmask是255.255.255.0;
2.另一方面查看gateway和DNS是什么:
Gateway:
$ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 172.16.*.* 0.0.0.0 UG 0 0 0 eno1 172.16.13.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
gateway为172.16.*.*
DNS:
$ cat /etc/resolv.conf # Generated by NetworkManager nameserver 159.226.*.*
DNS为159.226.*.*
3.得到需要的信息后,更改网络配置文件:
vim /etc/sysconfig/network-scripts/ifcfg-eno1
在最后加上下面这几句话:
IPADDR=172.16.13.196 GATEWAY=172.16.13.254 NETMASK=255.255.255.0 DNS1=159.226.8.6
同时把 BOOTPROTO="dhcp" 变更为 BOOTPROTO="static"
4.重启网络:
service network restart
Restarting network (via systemctl): [ OK ]
完成!
作者:丨o聽乄雨o丨
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。