您好,登录后才能下订单哦!
本篇内容介绍了“Centos7如何添加ip地址和网关”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
1.查看os版本
[root@oracle network-scripts]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
2.查看链接的是哪个网口,很多时候服务器上不只一个网口,本例就有4个,需要判断出目前网线插上的是哪个网口,本例是em1处于链接状态,那么配置ip的时候就配置这个em1
[root@oracle network-scripts]# nmcli dev status
DEVICE TYPE STATE CONNECTION
em2 ethernet unavailable --
p1p1 ethernet unavailable --
p1p2 ethernet unavailable --
em1 ethernet connected --
lo loopback unmanaged --
3.修改文件,红色是添加和修改的,BOOTPROTO=dhcp,从dhcp以后从改为static,
NM_CONTROLLED=no 表示该口将通过该配置文件进行设置,
ONBOOT=yes的意思是这个网卡开机自动启动。
vi /etc/sysconfig/network-scripts/ifcfg-em1
TYPE=Ethernet
BOOTPROTO=static
IPADDR=172.24.80.236
NETMASK=255.255.255.0
GATEWAY=172.24.80.1
NM_CONTROLLED=no
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=em1
UUID=67ac8318-e715-4081-9ef7-781140c62cb1
DEVICE=em1
ONBOOT=yes
4.重启服务
systemctl restart network.service
5.验证接口是否配置正确
[root@oracle network-scripts]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
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
valid_lft forever preferred_lft forever
2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether d0:94:66:3e:ae:d0 brd ff:ff:ff:ff:ff:ff
inet 172.24.80.236/24 brd 172.24.80.255 scope global em1
valid_lft forever preferred_lft forever
inet6 fe80::d294:66ff:fe3e:aed0/64 scope link
valid_lft forever preferred_lft forever
3: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether d0:94:66:3e:ae:d1 brd ff:ff:ff:ff:ff:ff
4: p1p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether d0:94:66:3e:bf:03 brd ff:ff:ff:ff:ff:ff
5: p1p2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
link/ether d0:94:66:3e:bf:04 brd ff:ff:ff:ff:ff:ff
6.查看网口状态
[root@oracle network-scripts]# nmcli dev status
DEVICE TYPE STATE CONNECTION
em2 ethernet unavailable --
p1p1 ethernet unavailable --
p1p2 ethernet unavailable --
em1 ethernet unmanaged --
lo loopback unmanaged --
“Centos7如何添加ip地址和网关”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。