Centos 7開始使用ip命令替換了之前的ifconfig網絡
ip [選項] 操做對象{link|addr|route...}
# ip link show # 顯示網絡接口信息
# ip link set eth0 upi # 開啓網卡
# ip link set eth0 down # 關閉網卡
# ip link set eth0 promisc on # 開啓網卡的混合模式
# ip link set eth0 promisc offi # 關閉網卡的混個模式
# ip link set eth0 txqueuelen 1200 # 設置網卡隊列長度
# ip link set eth0 mtu 1400 # 設置網卡最大傳輸單元
# ip addr show # 顯示網卡IP信息
# ip addr add 192.168.0.1/24 dev eth0 # 設置eth0網卡IP地址192.168.0.1
# ip addr del 192.168.0.1/24 dev eth0 # 刪除eth0網卡IP地址
# ip route list # 查看路由信息
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # 設置192.168.4.0網段的網關爲192.168.0.254,數據走eth0接口
# ip route add default via 192.168.0.254 dev eth0 # 設置默認網關爲192.168.0.254
# ip route del 192.168.4.0/24 # 刪除192.168.4.0網段的網關
# ip route del default # 刪除默認路由less
開啓自動獲取oop
首先查看本身的網卡信息post
ip addr showspa
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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff
可查看到網卡名稱爲eno16777736對象
進入network-scripts接口
[root@localhost ~]# cd /etc/sysconfig/network-scripts
[root@localhost network-scripts]# ls
ifcfg-eno16777736 ifdown-eth ifdown-isdn ifdown-sit ifup ifup-ib ifup-plip ifup-routes ifup-tunnel network-functions-ipv6
ifcfg-lo ifdown-ib ifdown-post ifdown-Team ifup-aliases ifup-ippp ifup-plusb ifup-sit ifup-wireless
ifdown ifdown-ippp ifdown-ppp ifdown-TeamPort ifup-bnep ifup-ipv6 ifup-post ifup-Team init.ipv6-global
ifdown-bnep ifdown-ipv6 ifdown-routes ifdown-tunnel ifup-eth ifup-isdn ifup-ppp ifup-TeamPort network-functions
[root@localhost network-scripts]#
隊列
能夠查看到咱們相應網卡的配置文件爲ifcfg-eno16777736ip
使用vi ifcfg-eno16777736路由
進入編輯
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=eno16777736
UUID=5b96b479-11f3-4aec-b984-129de5721e7b
DEVICE=eno16777736
ONBOOT=no
將ONBOOT=no修改成ONBOOT=yes並保存退出重啓
重啓後再次使用ip addr show可查看到
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: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff
inet 192.168.133.133/24 brd 192.168.133.255 scope global dynamic eno16777736
valid_lft 1252sec preferred_lft 1252sec
inet6 fe80::20c:29ff:fec9:9b0b/64 scope link
valid_lft forever preferred_lft forever
咱們網卡已經自動獲取到ip了
手工設置IP地址:
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=eno16777736
UUID=5b96b479-11f3-4aec-b984-129de5721e7b
DEVICE=eno16777736
ONBOOT=yes
IPADDR0=192.168.133.130
PREFIX0=24
GETWAY0=192.168.133.2
DNS1=192.68.133.2
DNS2=218.85.152.99
經過上面配置。咱們爲系統指定ip 子網掩碼 網關以及DNS地址。
[root@localhost ~]# ip addr show1: 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 forever2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:c9:9b:0b brd ff:ff:ff:ff:ff:ff inet 192.168.133.130/24 brd 192.168.133.255 scope global eno16777736 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fec9:9b0b/64 scope link valid_lft forever preferred_lft forever習慣使用ifconfig的能夠實現聯網後經過yum install net-tools安裝net-tools組件使用ifconfig。