CentOS6 設定靜態地址以及虛擬機器更換後(或拷貝來的虛擬機器)靜態地址無法連結問題

來源:互聯網
上載者:User

一、CentOS6 設定靜態地址

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=yes
NETWORKING_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 restart

5.避免重啟伺服器後DNS配置被清空

chkconfig NetworkManager off

二、虛擬機器更換後或拷貝後的虛擬機器靜態地址無法連結問題

1.虛擬機器更換後靜態地址無法串連問題

報錯如:device eth0 does not seem to be present, delaying initialization

(1)vi /etc/sysconfig/network-scripts/ifcfg-eth0

ifcfg-eth0的設定檔裡儲存了以前的MAC地址,就把這一行刪除掉在重啟網卡


(2)/etc/udev/rules.d/70-persistent-net.rules 刪除後重啟機器
因為這個檔案綁定了網卡和mac地址,所以換了網卡以後MAC地址變了,所以不能正常啟動,也可以直接編輯這個設定檔把裡面的網卡和mac地址修改乘對應的,不過這樣多麻煩,直接刪除重啟,它會自動產生個。

2.如果依然無法串連其他主機,請檢查本機及其他主機防火牆或網路連接設定

(1)永久關閉防火牆


查看當前防火牆狀態:/etc/init.d/iptables
status
會得到一系列資訊,說明防火牆開著。
/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


(3)重啟系統。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.