一、CentOS6 设置静态地址
BOOTPROTO=none
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.0.xx
NETMASK=255.255.255.0
NETWORK=192.168.0.0
GATEWAY=192.168.0.1
HWADDR=xx:xx:xx:xx:xx:xx
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
LAST_CONNECT=1358664214
NETWORKING_IPV6=no
HOSTNAME=xxxxxxxxxx
GATEWAY=192.168.0.1
/etc/init.d/NetworkManager stop
修改/etc/resolv.conf
vim /etc/resolv.conf
修改或新增dns地址:
nameserver xxx.xxx.xxx.xxx
保存退出
因为这个文件绑定了网卡和mac地址,所以换了网卡以后MAC地址变了,所以不能正常启动,也可以直接编辑这个配置文件把里面的网卡和mac地址修改乘对应的,不过这样多麻烦,直接删除重启,它会自动生成个。
会得到一系列信息,说明防火墙开着。
/etc/init.d/iptables stop
永久关闭:
chkconfig --level 35 iptables off
(2)永久关闭SELinux
查看当前SELinux状态:
/usr/bin/setstatus -v
编辑/etc/selinux/config,找到SELINUX 行修改成为:SELINUX=disabled:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
1.修改网卡配置 vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"BOOTPROTO=none
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
IPADDR=192.168.0.xx
NETMASK=255.255.255.0
NETWORK=192.168.0.0
GATEWAY=192.168.0.1
HWADDR=xx:xx:xx:xx:xx:xx
PREFIX=24
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
LAST_CONNECT=1358664214
2.修改网关配置 vi /etc/sysconfig/network
NETWORKING=yesNETWORKING_IPV6=no
HOSTNAME=xxxxxxxxxx
GATEWAY=192.168.0.1
3.修改DNS 配置 vi /etc/resolv.conf
关闭NetworkManager服务/etc/init.d/NetworkManager stop
修改/etc/resolv.conf
vim /etc/resolv.conf
修改或新增dns地址:
nameserver xxx.xxx.xxx.xxx
保存退出
4.重启网卡
/etc/init.d/network restart 或 service network restart5.避免重启服务器后DNS配置被清空
chkconfig NetworkManager off二、虚拟机更换后或拷贝后的虚拟机静态地址无法链接问题
1.虚拟机更换后静态地址无法连接问题
报错如:device eth0 does not seem to be present, delaying initialization
ifcfg-eth0的配置文件里保存了以前的MAC地址,就把这一行删除掉在重启网卡
因为这个文件绑定了网卡和mac地址,所以换了网卡以后MAC地址变了,所以不能正常启动,也可以直接编辑这个配置文件把里面的网卡和mac地址修改乘对应的,不过这样多麻烦,直接删除重启,它会自动生成个。
2.如果依然无法连接其他主机,请检查本机及其他主机防火墙或网络连接设置
(1)永久关闭防火墙
会得到一系列信息,说明防火墙开着。
/etc/init.d/iptables stop
永久关闭:
chkconfig --level 35 iptables off
(2)永久关闭SELinux
查看当前SELinux状态:
/usr/bin/setstatus -v
编辑/etc/selinux/config,找到SELINUX 行修改成为:SELINUX=disabled:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Only targeted network daemons are protected.
# strict - Full SELinux protection.
SELINUXTYPE=targeted