美文网首页
CentOS 6网络配置

CentOS 6网络配置

作者: 姜饼人_9e7b | 来源:发表于2017-07-09 21:03 被阅读0次

命令模式:

  • 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
#删除默认路由

相关文章

网友评论

      本文标题:CentOS 6网络配置

      本文链接:https://www.haomeiwen.com/subject/mvmshxtx.html