CentOS 6網絡配置

命令模式:

  • ifcfg:ifconfig, route, netstat
  • ip:object {link, addr, route}, ss, tc

圖形模式:

  • system-config-network-tui
  • setup

一、網卡

(1)修改網卡名

CentOS 6網卡名字默認是eth0、eth1...
網卡名配置文件 /etc/udev/rules.d/70-persistent-net.rules

[root@CentOS6 ~]#vim /etc/udev/rules.d/70-persistent-net.rules 
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ec:
f0:ac", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

只需要修改NAME=""這一項即可。修改后需要重新加載網卡驅動模塊才能生效。

(2)網卡驅動

ethtool -i eth0 查看驅動信息

[root@CentOS6 ~]#ethtool -i eth0
driver: e1000
version: 7.3.21-k8-NAPI
firmware-version: 
...
[root@CentOS6 ~]#lsmod |grep -i e1000
e1000                 134863  0 
#查看驅動模塊
[root@CentOS6 ~]#modprobe -r e1000
#卸載驅動模塊,注意:卸載后會斷網
[root@CentOS6 ~]#modprobe  e1000
#加載驅動模塊

二、網絡配置

1、ifconfig命令

ifconfig interface [aftype] options | address ...

ifconfig -a
#查看所有網卡信息,包括被禁用的網卡
ifconfig eth1 up
#啟用eth1網卡數據鏈路層
ifconfig eth1 192.168.43.101/24
#配置eth1的IP為192.168.43.101/24
ifdown eth1
#從網絡層禁用eth1
ifup eth1
#從網絡層啟用eth1

2、route命令

查看:

route -n 
#查看路由表

添加

route add -net  default gw 192.168.43.10 dev eth0
#添加默認路由
route del -net  172.16.1.0/16 gw 192.168.43.10 dev eth0
#刪除172.16.1.0/16的路由
#如果是主機路由,就把-net改成-host

3、ip命令

ip [ OPTIONS ] OBJECT { COMMAND | help }

  • OBJECT:link、addr、route
  • COMMAN:set、show

查看:

ip link
#查看網卡數據鏈路層信息
ip addr
#查看網卡網絡層信息
ip route
#查看路由表
ip addr show ens33
#查看網卡ens33網絡層信息

** 配置:**

  • IP地址
ip link set eth1 up
#啟用網卡eth1
ip addr add 172.0.0.0/8 dev eth1 label home
#配置eth1的ip,并且加上標簽“home”。標簽只是個備注說明,可以不加。重復使用這個命令可以給一個網卡配置多個ip
ip addr del 172.0.0.0/8 dev eth1
#刪除eth1的ip

  • 路由
ip route add 192.168.1.0/24 via 172.16.0.1
#添加路由信息
ip route add default via 172.16.0.1
#添加默認路由
ip route del default via 172.16.0.1
#刪除默認路由
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容