Fedora ifconfig配置網(wǎng)絡(luò)接口
Fedora ifconfig 是一個(gè)用來查看、配置、啟用或禁用網(wǎng)絡(luò)接口的工具,這個(gè)工具極為常用的??梢杂眠@個(gè)工具來臨時(shí)性的配置網(wǎng)卡的IP地址、掩碼、廣播地址、網(wǎng)關(guān)等。也可以把它寫入一個(gè)文件中(比如/etc/rc.d/rc.local),這樣系統(tǒng)引導(dǎo)后,會(huì)讀取這個(gè)文件,為網(wǎng)卡設(shè)置IP地址。
1、Fedora ifconfig 查看網(wǎng)絡(luò)接口狀態(tài)Fedora ifconfig 如果不接任何參數(shù),就會(huì)輸出當(dāng)前網(wǎng)絡(luò)接口的情況:
- [root@localhost ~]# Fedora ifconfig
- eth0 Link encap:Ethernet HWaddr 00:C0:9F:94:78:0E
- inet addr:192.168.1.88 Bcast:192.168.1.255 Mask:255.255.255.0
- inet6 addr: fe80::2c0:9fff:fe94:780e/64 Scope:Link
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- RX packets:850 errors:0 dropped:0 overruns:0 frame:0
- TX packets:628 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:369135 (360.4 KiB) TX bytes:75945 (74.1 KiB)
- Interrupt:10 Base address:0x3000
- 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:57 errors:0 dropped:0 overruns:0 frame:0
- TX packets:57 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:0
- RX bytes:8121 (7.9 KiB) TX bytes:8121 (7.9 KiB)注解:
eth0 表示***塊網(wǎng)卡, 其中 HWaddr 表示網(wǎng)卡的物理地址,可以看到目前這個(gè)網(wǎng)卡的物理地址(MAC地址)是 00:C0:9F:94:78:0E ; inet addr 用來表示網(wǎng)卡的IP地址,此網(wǎng)卡的 IP地址是 192.168.1.88,廣播地址, Bcast:192.168.1.255,掩碼地址Mask:255.255.255.0。
lo 是表示主機(jī)的回環(huán)地址,這個(gè)一般是用來測(cè)試一個(gè)網(wǎng)絡(luò)程序,但又不想讓局域網(wǎng)或外網(wǎng)的用戶能夠查看,只能在此臺(tái)主機(jī)上運(yùn)行和查看所用的網(wǎng)絡(luò)接口。比如把 HTTPD服務(wù)器的指定到回壞地址,在瀏覽器輸入 127.0.0.1 就能看到你所架WEB網(wǎng)站了。但只是您能看得到,局域網(wǎng)的其它主機(jī)或用戶無從知道。
如果想知道主機(jī)所有網(wǎng)絡(luò)接口的情況,請(qǐng)用下面的命令:[root@localhost ~]# Fedora ifconfig -a
如果想查看某個(gè)端口,比如查看eth0 的狀態(tài),就可以用下面的方法:[root@localhost ~]# Fedora ifconfig eth0
2、Fedora ifconfig 配置網(wǎng)絡(luò)接口
Fedora ifconfig 可以用來配置網(wǎng)絡(luò)接口的IP地址、掩碼、網(wǎng)關(guān)、物理地址等;值得一說的是用Fedora ifconfig 為網(wǎng)卡指定IP地址,這只是用來調(diào)試網(wǎng)絡(luò)用的,并不會(huì)更改系統(tǒng)關(guān)于網(wǎng)卡的配置文件。
如果您想把網(wǎng)絡(luò)接口的IP地址固定下來,目前有三個(gè)方法:一是通過各個(gè)發(fā)行和版本專用的工具來修改IP地址;二是直接修改網(wǎng)絡(luò)接口的配置文件;三是修改特定的文件,加入Fedora ifconfig 指令來指定網(wǎng)卡的IP地址,比如在redhat或Fedora中,把Fedora ifconfig 的語(yǔ)名寫入/etc/rc.d/rc.local文件中。
Fedora ifconfig 配置網(wǎng)絡(luò)端口的方法:Fedora ifconfig 工具配置網(wǎng)絡(luò)接口的方法是通過指令的參數(shù)來達(dá)到目的的,我們只說最常用的參數(shù):Fedora ifconfig 網(wǎng)絡(luò)端口 IP地址 hw <HW> MAC地址 netmask 掩碼地址 broadcast 廣播地址 [up/down]* 實(shí)例一:比如我們用Fedora ifconfig 來調(diào)試 eth0網(wǎng)卡的地址
- [root@localhost ~]# Fedora ifconfig eth0 down
- [root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
- [root@localhost ~]# Fedora ifconfig eth0 up
- [root@localhost ~]# Fedora ifconfig eth0
- eth0 Link encap:Ethernet HWaddr 00:11:00:00:11:11
- inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0
- UP BROADCAST MULTICAST MTU:1500 Metric:1
- RX packets:0 errors:0 dropped:0 overruns:0 frame:0
- TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
- collisions:0 txqueuelen:1000
- RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
- Interrupt:11 Base address:0x3400
注解:
- ***行:Fedora ifconfig eth0 down 表示如果eth0是激活的,就把它DOWN掉。此命令等同于 ifdown eth0;
- 第二行:用Fedora ifconfig 來配置 eth0的IP地址、廣播地址和網(wǎng)絡(luò)掩碼;
- 第三行:用Fedora ifconfig eth0 up 來激活eth0 ; 此命令等同于 ifup eth0
- 第四行:用 Fedora ifconfig eth0 來查看 eth0的狀態(tài)。
當(dāng)然您也可以用直接在指令I(lǐng)P地址、網(wǎng)絡(luò)掩碼、廣播地址的同時(shí)激活網(wǎng)卡,要加up參數(shù)。比如下面的例子:
- [root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0 up
- [root@localhost ~]# Fedora ifconfig eth0 down
- [root@localhost ~]# Fedora ifconfig eth0 192.168.1.99 broadcast 192.168.1.255 netmask 255.255.255.0
- [root@localhost ~]# Fedora ifconfig eth0 up
- [root@localhost ~]# Fedora ifconfig eth0
* 實(shí)例二:在這個(gè)例子中,我們要學(xué)會(huì)設(shè)置網(wǎng)絡(luò)IP地址的同時(shí),學(xué)會(huì)設(shè)置網(wǎng)卡的物理地址(MAC地址);
比如我們?cè)O(shè)置網(wǎng)卡eth1的IP地址、網(wǎng)絡(luò)掩碼、廣播地址,物理地址并且激活它。
- [root@localhost ~]# Fedora ifconfig eth1 192.168.1.252 hw ether 00:11:00:00:11:11 netmask 255.255.255.0 broadcast 192.168.1.255 up或
- [root@localhost ~]# Fedora ifconfig eth1 hw ether 00:11:00:00:11:22
- [root@localhost ~]# Fedora ifconfig eth1 192.168.1.252 netmask 255.255.255.0 broadcast 192.168.1.255 up
其中 hw 后面所接的是網(wǎng)絡(luò)接口類型, ether表示乙太網(wǎng), 同時(shí)也支持 ax2***RCnet、netrom等,詳情請(qǐng)查看 man Fedora ifconfig。
3、用Fedora ifconfig 來配置虛擬網(wǎng)絡(luò)接口
有時(shí)我們?yōu)榱藵M足不同的需要還需要配置虛擬網(wǎng)絡(luò)接口,比如我們用不同的IP地址來架運(yùn)行多個(gè)HTTPD服務(wù)器,就要用到虛擬地址;這樣就省卻了同一個(gè)IP地址,如果開設(shè)兩個(gè)的HTTPD服務(wù)器時(shí),要指定端口號(hào)。
虛擬網(wǎng)絡(luò)接口指的是為一個(gè)網(wǎng)絡(luò)接口指定多個(gè)IP地址,虛擬接口是這樣的 eth0:0、 eth0:1、eth0:2 ... .. eth1N。當(dāng)然您為 eth1 指定多個(gè)IP地址,也就是 eth1:0、eth1:1、eth1:2 ... ...以此類推。
其實(shí)用Fedora ifconfig 為一個(gè)網(wǎng)卡配置多個(gè)IP地址,就用前面我們所說的Fedora ifconfig的用法,這個(gè)比較簡(jiǎn)單??聪旅娴睦樱?/p>
- [root@localhost ~]# Fedora ifconfig eth1:0 192.168.1.251 hw ether 00:11:00:00:11:33 netmask 255.255.255.0 broadcast 192.168.1.255 up或
- [root@localhost ~]# Fedora ifconfig eth1 hw ether 00:11:00:00:11:33
- [root@localhost ~]# Fedora ifconfig eth1 192.168.1.251 netmask 255.255.255.0 broadcast 192.168.1.255 up
注意:指定時(shí),要為每個(gè)虛擬網(wǎng)卡指定不同的物理地址。在 Redhat/Fedora 或與Redhat/Fedora類似的系統(tǒng),您可以把配置網(wǎng)絡(luò)IP地址、廣播地址、掩碼地址、物理地址以及激活網(wǎng)絡(luò)接口同時(shí)放在一個(gè)句子中,寫入/etc/rc.d/rc.local中。比如下面的例子;
Fedora ifconfig eth1:0 192.168.1.250 hw ether 00:11:00:00:11:44 netmask 255.255.255.0 broadcast 192.168.1.255 up
Fedora ifconfig eth1:1 192.168.1.249 hw ether 00:11:00:00:11:55 netmask 255.255.255.0 broadcast 192.168.1.255 up
解說:上面是為eth1的網(wǎng)絡(luò)接口,設(shè)置了兩個(gè)虛擬接口,每個(gè)接口都有自己的物理地址、IP地址... ...
【編輯推薦】