1.檢視網絡MAC位址
[[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules
顯示如下資訊
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:94:04:3c", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x15ad:0x07b0 (vmxnet3)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:50:56:94:53:24", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
eth0:對應第一張網卡,eth1:對就第二張網卡。目前使用eth0連接配接路由器,eth1保留(伺服器一般用來,連接配接其它主機)
2.修改主機名稱
[[email protected] ~]# vim /etc/sysconfig/network
打開檔案,修改以下内容并儲存
NETWORKING=yes #使用網絡
HOSTNAME=centos #設定主機名稱
3.修改網卡
[[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
打開檔案,修改以下内容并儲存
DEVICE=eth0 #對應第一張網卡
HWADDR=00:50:56:94:04:3C #必須對應etho是的MAC位址(/etc/udev/rules.d/70-persistent-net.rules)
TYPE=Ethernet #網卡類型
UUID=b79**** #這是自動生成的
ONBOOT=yes #是否啟動時運作
NM_CONTROLLED=yes
BOOTPROTO=static #啟用位址協定 --static:靜态協定 --bootp協定 --dhcp協定
#以上是系統自帶的,下面是手動添加的。
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0" #名稱
PEERDNS=yes
PEERROUTES=yes
IPADDR=192.168.1.253 #指定本機IP位址
NETMASK=255.255.255.0 #指定子網路遮罩
GATEWAY=192.168.1.1 指定網關
4.修改DNS
[[email protected] ~]# vim /etc/resolv.conf
打開檔案,修改以下内容并儲存
nameserver 8.8.8.8 #GOOGLE的DNS伺服器
nameserver 61.144.56.100 #指定目前城市最近的DNS伺服器(各城市不一樣,上網搜尋)
nameserver 192.168.1.1 #指定經路由器上指定的DNS伺服器
5.重新啟動網絡配置
[[email protected] ~]#service network restart
注:
如果出現提示Determining if ip address X.X.X.X is already in use for device eth0。
是因為linux網卡配置arp檢查導緻的,把這個關掉即可。
在網卡配置檔案裡面添加 ARPCHECK=no , 然後再重新執行 service network restart 即可。
執行 restart 後 /etc/resolv.conf 檔案可能會被覆寫掉,需要将這個的屬性設定為隻讀,隻有 root 使用者可以修改。
具體辦法是運作以下指令:
$ chattr +i /etc/resolv.conf , 該指令修改檔案屬性為隻有 root 使用者才能修改該檔案。去掉可将參數改為 “-i”。
或者重新開機網卡
[[email protected] ~]# /etc/init.d/network stop
[[email protected] ~]# /etc/init.d/network start
6.重新開機
[[email protected] ~]#shutdown -r now
7.檢視目前IP設定
[[email protected] ~]# ifconfig
如果仍然隻有 lo而沒有 eth0 則說明eth0 沒有啟動
激活eth0 [[email protected] ~]# ifup eth0 #啟動網絡
8.測試是否連接配接外網
[[email protected] ~]# ping www.163.com
網卡接口關閉與激活
[[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
----------------------------------------------------------------
以下是參考,如果按上面步驟不行,可以詳細看以下内容:
網絡接口配置檔案
[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
TYPE=Ethernet #網卡類型
DEVICE=eth0 #網卡接口名稱
ONBOOT=yes #系統啟動時是否自動加載
BOOTPROTO=static #啟用位址協定 --static:靜态協定 --bootp協定 --dhcp協定
IPADDR=192.168.1.11 #網卡IP位址
NETMASK=255.255.255.0 #網卡網絡位址
GATEWAY=192.168.1.1 #網卡網關位址
DNS1=10.203.104.41 #網卡DNS位址
HWADDR=00:0C:29:13:5D:74 #網卡裝置MAC位址
BROADCAST=192.168.1.255 #網卡廣播位址
重新導入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
eth0 Link encap:Ethernet HWaddr 00:0C:29:13:5D:74
inet addr:192.168.1.11 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe13:5d74/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:413 errors:0 dropped:0 overruns:0 frame:0
TX packets:572 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:47701 (46.5 KiB) TX bytes:64842 (63.3 KiB)
Base address:0x2000 Memory:d8920000-d8940000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:407 errors:0 dropped:0 overruns:0 frame:0
TX packets:407 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:70759 (69.1 KiB) TX bytes:70759 (69.1 KiB)
檢視目前路由及網關資訊
[[email protected] ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0DNS:主機名:CentOS主DNS:202.106.46.151
第二
DNS:202.106.0.20
第三
DNS:8.8.8.8網絡配 置:
eth0靜态ip:192.168.1.106
子網路遮罩 255.255.255.0
預設網關 IP 192.168.1.1
DEVICE=eth0
IPADDR=192.168.1.106
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
ONBOOT=yes
BOOTPROTO=none
GATEWAY=192.168.1.1
TYPE=Ethernet
"/etc/sysconfig/network-scripts/ifcfg-eth0"
原文網址: http://www.cnblogs.com/vicowong/archive/2011/04/23/2025545.html