Centos 7 配置静态ip方法

前端之家收集整理的这篇文章主要介绍了Centos 7 配置静态ip方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

作为服务器还是静态ip比较靠谱;


ip管理主文件存放于/etc/sysconfig/network-scripts/ 目录

查看文件文件

#ls/etc/sysconfig/network-scripts/
ifcfg-eno1ifdown-bnepifdown-ipppifdown-postifdown-sitifdown-tunnelifup-bnepifup-ipppifup-plipifup-pppifup-Teamifup-wirelessnetwork-functions-ipv6
ifcfg-loifdown-ethifdown-ipv6ifdown-pppifdown-Teamifupifup-ethifup-ipv6ifup-plusbifup-routesifup-TeamPortinit.ipv6-global
ifdownifdown-ibifdown-isdnifdown-routesifdown-TeamPortifup-aliasesifup-ibifup-isdnifup-postifup-sitifup-tunnelnetwork-functions

CentOS默认使用第一个文件ifcfg-eno1作为主配置;#每个机器可能不同,以显示为准

查看eno1配置:

#cat/etc/sysconfig/network-scripts/ifcfg-eno1
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno1
UUID=ea4bbbab-1804-46df-b8f9-1451e5a710fc
DEVICE=eno1
ONBOOT=no

主要修改标识如下

#vi/etc/sysconfig/network-scripts/ifcfg-eno1

使用 i 进入INSERT操作进而编辑

TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=eno1
UUID=ea4bbbab-1804-46df-b8f9-1451e5a710fc
DEVICE=eno1
ONBOOT=yes
IPADDR=192.168.1.45
GATEWAY=192.168.1.1
NETMASK=255.255.255.0
DNS1=192.168.1.1

说明如下:

BOOTPROTO=static#使用static配置
ONBOOT=yes#开机启用本配置
IPADDR=192.168.1.45#静态IP
GATEWAY=192.168.1.1#默认网关
NETMASK=255.255.255.0#子网掩码
DNS1=192.168.1.1#DNS配置


# systemctl restart network.service 重启网络服务


# ip addr 查看静态ip

1:lo:mtu65536qdiscnoqueuestateUNKNOWN
link/loopback00:00:00:00:00:00brd00:00:00:00:00:00
inet127.0.0.1/8scopehostlo
valid_lftforeverpreferred_lftforever
inet6::1/128scopehost
valid_lftforeverpreferred_lftforever
2:eno1:mtu1500qdiscpfifo_faststateUPqlen1000
link/ether6c:0b:84:3c:70:efbrdff:ff:ff:ff:ff:ff
inet192.168.1.45/24brd192.168.1.255scopeglobaleno1
valid_lftforeverpreferred_lftforever
inet6fe80::6e0b:84ff:fe3c:70ef/64scopelink
valid_lftforeverpreferred_lftforever

可见已经生效


# ping 192.168.1.52 测试局域网内联通性

PING 192.168.1.52 (192.168.1.52) 56(84) bytes of data.

64 bytes from 192.168.1.52: icmp_seq=1 ttl=64 time=0.864 ms

64 bytes from 192.168.1.52: icmp_seq=2 ttl=64 time=0.464 ms

ps:最好在路由器侧对ip和mac静态绑定,以便后续恢复!


-------------------------------------

在部分情况下,ifcfg文件内部有“”,我们再添加修改时要全部保留,否则会报错;

另外最后的DNS1改成DNS时偶尔也会不识别,按说明不应该报错,待确认...

原文链接:https://www.f2er.com/centos/380719.html

猜你在找的CentOS相关文章