CentOS 网络配置
IP 网络接口配置文件
[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
DEVICE=eth0 #网卡接口名称
TYPE=Ethernet #网卡类型
ONBOOT=yes #系统启动时是否自动加载
BOOTPROTO=static #启用地址协议 --static:静态协议 --bootp协议 --dhcp协议
HWADDR=08:00:27:11:50:F5 #网卡设备MAC地址
IPADDR=10.243.118.152 #网卡IP地址
NETMASK=255.255.254.0 #网卡网络地址
GATEWAY=10.243.118.1 #网卡网关地址
BROADCAST=10.243.119.255 #网卡广播地址
DNS1=10.243.101.62 #网卡DNS地址
DNS2=10.243.65.66
重新导入ifcfg-eth0网络配置文件
[[email protected] ~]# /etc/init.d/network reload
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
网卡接口关闭与**
[[email protected] ~]# ifdown eth0 #关闭网络
[[email protected] ~]# ifup eth0 #启动网络
网络服务启动与关闭
方法一:
[[email protected] ~]# service network stop #关闭网络服务
[[email protected] ~]# service network start #启动网络服务
[[email protected] ~]# service network restart #重启网络服务
方法二:
[[email protected] ~]# /etc/init.d/network stop
[[email protected] ~]# /etc/init.d/network start
[[email protected] ~]# /etc/init.d/network restart
网卡状态查询
[[email protected] ~]# service network status
Configured devices:
lo eth0
Currently active devices:
lo eth0
临时配置网卡信息,无需重启。
[[email protected] ~]# ifconfig eth0 10.1.1.10 netmask 255.0.0.0
查看网卡接口信息,默认列出所有接口
[[email protected] ~]# ifconfig
查看当前路由及网关信息
[[email protected] ~]# netstat -r
redhat 脚本自动切换IP设置
Attached please find the script to change your vm’s network ip, the way to use it is as below:
1. Change to home’s network:
./changeNetwork.sh home
2. Change to office’s network:
./changeNetwork.sh office
changeNetwork.sh
\cp -f ifcfg-eth0-$1 /etc/sysconfig/network-scripts/ifcfg-eth0 service network restart
ifcfg-eth0-home
DEVICE=eth0
NM_CONTROLLED=yes
ONBOOT=yes
HWADDR=08:00:27:67:4D:66
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
IPADDR=192.168.1.123
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
USERCTL=no
DNS2=122.224.9.93
DNS1=8.8.8.8
ifcfg-eth0-office
DEVICE=eth0
NM_CONTROLLED=yes
ONBOOT=yes
HWADDR=08:00:27:7a:1c:cc
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=10.243.119.226
NETMASK=255.255.254.0
GATEWAY=10.243.119.1
USERCTL=no
DNS2=10.243.65.66
DNS1=10.243.101.62
设置暂时性的http代理 :
export http_proxy=http://username:[email protected]:port
查看端口占用情况 netstat -antlp | grep 443
bin/apachectl stop
bin/apachectl start
查看路由状态
tracert 192.168.67.143 4001
开通组播功能:
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
注意 : 如果提示 Error: No suitable device found: 找不到设备
删除 /etc/udev/rules.d/70-persistent-net.rules
重后 重新编辑使 mac 地址 及 设备名称 在两个文件中 对应