您好,登錄后才能下訂單哦!
本篇內容介紹了“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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。