linux下網卡配置的使用方法

來源:互聯網
上載者:User

標籤:centos   linux   ifconfig   網卡配置   

使用環境為CentOS6.6版本;


1、查看網卡IP地址    ifconfig

網卡設定檔:/etc/sysconfig/network-scripts/ifcfg-eth0 

如果有多個網卡的話為eth1、eth2 。。。

如果linux有多個網卡,只想重啟某一個網卡使用命令# ifdown eth0; ifup eth0

ifdown 停掉網卡,ifup 啟動網卡;

650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat center;border:1px solid #ddd;" alt="spacer.gif" />650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/6B/A0/wKioL1Uze1WRD421AABgTjCyHzg514.jpg" title="QQ圖片20150416171210.png" alt="wKioL1Uze1WRD421AABgTjCyHzg514.jpg" />

如果我們遠程登入伺服器,使用ifdown eth0 停掉網卡後,後面的命令不會被運行,會導致斷網無法串連伺服器。所以請盡量使用 service network restart 重啟網卡;


2、給一個網卡設定多個IP

[[email protected] ~]# cd /etc/sysconfig/network-scripts/[[email protected] network-scripts]# cp ifcfg-eth0 ifcfg-eth0\:1

編輯ifcfg-eth0:1 這個設定檔,更改裡面的DEVICE=eth0:1 設定新的IP地址192.168.20.30 ;

[[email protected] network-scripts]# vim ifcfg-eth0:1DEVICE=eth0:1HWADDR=00:0C:29:43:3D:32TYPE=EthernetUUID=0b1f4512-cefa-4a9e-ae85-adb2ac2a9903ONBOOT=yesNM_CONTROLLED=yesBOOTPROTO=staticIPADDR=192.168.20.30NETMASK=255.255.255.0GATEWAY=192.168.20.1

儲存退出後,重啟網卡;

[[email protected] network-scripts]# service network restart

[[email protected] network-scripts]# ifconfig eth0      Link encap:Ethernet  HWaddr 00:0C:29:43:3D:32            inet addr:192.168.20.20  Bcast:192.168.20.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe43:3d32/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:62506 errors:0 dropped:0 overruns:0 frame:0          TX packets:82867 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:38679452 (36.8 MiB)  TX bytes:47133078 (44.9 MiB)          Interrupt:18 Base address:0x2000 eth0:1    Link encap:Ethernet  HWaddr 00:0C:29:43:3D:32            inet addr:192.168.20.30  Bcast:192.168.20.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          Interrupt:18 Base address:0x2000

可以看到多了一個IP,可以用遠程ssh訪問這個192.168.20.30;



3、查看網卡串連狀態   mii-tool eth0

[[email protected] ~]# mii-tool eth0SIOCGMIIPHY on ‘eth0‘ failed: Operation not supported

由於是虛擬機器所以顯示"operation not supported",真實機器會顯示    eth0: negotiated 100baseTx-FD, link ok ;”link ok“說明網卡為串連狀態,如果顯示“no link“說明網卡壞掉了或沒有串連網線。


4、更改主機名稱

hostname    查看系統的主機名稱;

hostname 主機名稱    可以更改主機名稱,下次登入時會更改登入提示符;這樣更改只是暫時儲存在記憶體中,重啟後不會生效;

[[email protected] ~]# hostname yonglinux.com[[email protected] ~]# hostnameAngel[[email protected] ~]# hostnameAngel[[email protected] ~]# hostname Angel


永久更改主機名稱,需要編輯設定檔 /etc/sysconfig/network,更改HOSTNAME,儲存退出後重啟生效;

NETWORKING=yes

HOSTNAME=yonglinux.com


5、設定DNS

DNS為網域名稱解析,把網域名稱解析為ip地址;

設定檔為/etc/resolv.conf

[[email protected] ~]# cat /etc/resolv.conf ; generated by /sbin/dhclient-scriptnameserver 192.168.20.2

可以添加多個DNS地址,格式為:nameserver ip地址


linux下還有一個特殊的檔案 /etc/hosts 也可以解析網域名稱

手動在裡面添加ip地址 網域名稱地址;主要作用是臨時解析某個網域名稱。

格式為:ip地址 網域名稱    192.168.1.111 www.baidu.com

[[email protected] ~]# ping www.baidu.comPING www.baidu.com (192.168.1.111) 56(84) bytes of data.

幾點要注意的:

1)一個ip後面可以跟多個網域名稱,空格分隔開,可以是幾十個甚至幾百個;

2)每行只能有一個IP,也就是說一個網域名稱不能對應多個IP;

3)如果有多行中出現相同的網域名稱(ip不一樣)會按最前面出現的記錄來解析;



本文出自 “模範生的學習部落格” 部落格,請務必保留此出處http://8802265.blog.51cto.com/8792265/1635785

linux下網卡配置的使用方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.