Centos 7 新增ip地址和閘道器

甲骨文技術支援發表於2018-03-27

1.檢視os版本

  1. [root@oracle network-scripts]# cat /etc/redhat-release
  2. CentOS Linux release 7.2.1511 (Core)
2.檢視連結的是哪個網口,很多時候伺服器上不只一個網口,本例就有4個,需要判斷出目前網線插上的是哪個網口,本例是em1處於連結狀態,那麼配置ip的時候就配置這個em1


  1. [root@oracle network-scripts]# nmcli dev status
  2. DEVICE TYPE STATE CONNECTION
  3. em2 ethernet unavailable --
  4. p1p1 ethernet unavailable --
  5. p1p2 ethernet unavailable --
  6. em1 ethernet connected    --
  7. lo loopback unmanaged --
3.修改檔案,紅色是新增和修改的,BOOTPROTO=dhcp,從dhcp以後從改為static,

NM_CONTROLLED=no 表示該口將透過該配置檔案進行設定,
ONBOOT=yes的意思是這個網路卡開機自動啟動。

vi /etc/sysconfig/network-scripts/ifcfg-em1

  1. TYPE=Ethernet
  2. BOOTPROTO=static
  3. IPADDR=172.24.80.236
  4. NETMASK=255.255.255.0
  5. GATEWAY=172.24.80.1
  6. NM_CONTROLLED=no
  7. DEFROUTE=yes
  8. PEERDNS=yes
  9. PEERROUTES=yes
  10. IPV4_FAILURE_FATAL=no
  11. IPV6INIT=yes
  12. IPV6_AUTOCONF=yes
  13. IPV6_DEFROUTE=yes
  14. IPV6_PEERDNS=yes
  15. IPV6_PEERROUTES=yes
  16. IPV6_FAILURE_FATAL=no
  17. NAME=em1
  18. UUID=67ac8318-e715-4081-9ef7-781140c62cb1
  19. DEVICE=em1
  20. ONBOOT=yes
4.重啟服務

  1. systemctl restart network.service
5.驗證介面是否配置正確

  1. [root@oracle network-scripts]# ip add
  2. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
  3.     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  4.     inet 127.0.0.1/8 scope host lo
  5.        valid_lft forever preferred_lft forever
  6.     inet6 ::1/128 scope host
  7.        valid_lft forever preferred_lft forever
  8. 2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
  9.     link/ether d0:94:66:3e:ae:d0 brd ff:ff:ff:ff:ff:ff
  10.     inet 172.24.80.236/24 brd 172.24.80.255 scope global em1
  11.        valid_lft forever preferred_lft forever
  12.     inet6 fe80::d294:66ff:fe3e:aed0/64 scope link
  13.        valid_lft forever preferred_lft forever
  14. 3: em2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
  15.     link/ether d0:94:66:3e:ae:d1 brd ff:ff:ff:ff:ff:ff
  16. 4: p1p1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
  17.     link/ether d0:94:66:3e:bf:03 brd ff:ff:ff:ff:ff:ff
  18. 5: p1p2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
  19.     link/ether d0:94:66:3e:bf:04 brd ff:ff:ff:ff:ff:ff
6.檢視網口狀態

  1. [root@oracle network-scripts]# nmcli dev status
  2. DEVICE TYPE STATE CONNECTION
  3. em2 ethernet unavailable --
  4. p1p1 ethernet unavailable --
  5. p1p2 ethernet unavailable --
  6. em1 ethernet unmanaged --
  7. lo loopback unmanaged --

7.nmtui是使用網路管理器管理網口的命令









來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20893244/viewspace-2152261/,如需轉載,請註明出處,否則將追究法律責任。

相關文章