新聞中心
Linux怎么設(shè)置IP,子網(wǎng)掩碼和網(wǎng)關(guān)
linux一般使用ifconfig命令修改linux主機(jī)的ip、網(wǎng)關(guān)或子網(wǎng)掩碼。 1.命令格式: ifconfig [網(wǎng)絡(luò)設(shè)備] [參數(shù)] 2.命令功能: ifconfig 命令用來(lái)查看和配置網(wǎng)絡(luò)設(shè)備。當(dāng)網(wǎng)絡(luò)環(huán)境發(fā)生改變時(shí)可通過(guò)此命令對(duì)網(wǎng)絡(luò)進(jìn)行相應(yīng)的配置。 3.命令參數(shù): up 啟動(dòng)指定網(wǎng)絡(luò)設(shè)備/網(wǎng)卡。 down 關(guān)閉指定網(wǎng)絡(luò)設(shè)備/網(wǎng)卡。該參數(shù)可以有效地阻止通過(guò)指定接口的IP信息流,如果想永久地關(guān)閉一個(gè)接口,我們還需要從核心路由表中將該接口的路由信息全部刪除。 arp 設(shè)置指定網(wǎng)卡是否支持ARP協(xié)議。 -promisc 設(shè)置是否支持網(wǎng)卡的promiscuous模式,如果選擇此參數(shù),網(wǎng)卡將接收網(wǎng)絡(luò)中發(fā)給它所有的數(shù)據(jù)包 -allmulti 設(shè)置是否支持多播模式,如果選擇此參數(shù),網(wǎng)卡將接收網(wǎng)絡(luò)中所有的多播數(shù)據(jù)包 -a 顯示全部接口信息 -s 顯示摘要信息(類似于 netstat -i) add 給指定網(wǎng)卡配置IPv6地址 del 刪除指定網(wǎng)卡的IPv6地址 硬件地址 配置網(wǎng)卡最大的傳輸單元 mtu字節(jié)數(shù) 設(shè)置網(wǎng)卡的最大傳輸單元 (bytes) netmask子網(wǎng)掩碼 設(shè)置網(wǎng)卡的子網(wǎng)掩碼。掩碼可以是有前綴0x的32位十六進(jìn)制數(shù),也可以是用點(diǎn)分開(kāi)的4個(gè)十進(jìn)制數(shù)。如果不打算將網(wǎng)絡(luò)分成子網(wǎng),可以不管這一選項(xiàng);如果要使用子網(wǎng),那么請(qǐng)記住,網(wǎng)絡(luò)中每一個(gè)系統(tǒng)必須有相同子網(wǎng)掩碼。 tunel 建立隧道 dstaddr 設(shè)定一個(gè)遠(yuǎn)端地址,建立點(diǎn)對(duì)點(diǎn)通信 -broadcast地址 為指定網(wǎng)卡設(shè)置廣播協(xié)議 -pointtopoint地址 為網(wǎng)卡設(shè)置點(diǎn)對(duì)點(diǎn)通訊協(xié)議 multicast 為網(wǎng)卡設(shè)置組播標(biāo)志 address 為網(wǎng)卡設(shè)置IPv4地址 txqueuelen長(zhǎng)度 為網(wǎng)卡設(shè)置傳輸列隊(duì)的長(zhǎng)度 4.使用實(shí)例: 實(shí)例1:顯示網(wǎng)絡(luò)設(shè)備信息(激活狀態(tài)的) 命令: ifconfig 輸出:[root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:68 errors:0 dropped:0 overruns:0 frame:0TX packets:68 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)說(shuō)明: eth0 表示第一塊網(wǎng)卡, 其中 HWaddr 表示網(wǎng)卡的物理地址,可以看到目前這個(gè)網(wǎng)卡的物理地址(MAC地址)是 00:50:56:BF:26:20 inet addr 用來(lái)表示網(wǎng)卡的IP地址,此網(wǎng)卡的 IP地址是 192.168.120.204,廣播地址, Bcast:192.168.120.255,掩碼地址Mask:255.255.255.0 lo 是表示主機(jī)的回壞地址,這個(gè)一般是用來(lái)測(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ī)或用戶無(wú)從知道。 第一行:連接類型:Ethernet(以太網(wǎng))HWaddr(硬件mac地址) 第二行:網(wǎng)卡的IP地址、子網(wǎng)、掩碼 第三行:UP(代表網(wǎng)卡開(kāi)啟狀態(tài))RUNNING(代表網(wǎng)卡的網(wǎng)線被接上)MULTICAST(支持組播)MTU:1500(最大傳輸單元):1500字節(jié) 第四、五行:接收、發(fā)送數(shù)據(jù)包情況統(tǒng)計(jì) 第七行:接收、發(fā)送數(shù)據(jù)字節(jié)數(shù)統(tǒng)計(jì)信息。 實(shí)例2:?jiǎn)?dòng)關(guān)閉指定網(wǎng)卡 命令: ifconfig eth0 up ifconfig eth0 down 輸出: 說(shuō)明: ifconfig eth0 up 為啟動(dòng)網(wǎng)卡eth0 ;ifconfig eth0 down 為關(guān)閉網(wǎng)卡eth0。ssh登陸linux服務(wù)器操作要小心,關(guān)閉了就不能開(kāi)啟了,除非你有多網(wǎng)卡。實(shí)例3:為網(wǎng)卡配置和刪除IPv6地址 命令: ifconfig eth0 add 33ffe:3240:800:1005::2/64 ifconfig eth0 del 33ffe:3240:800:1005::2/64 輸出: 說(shuō)明: ifconfig eth0 add 33ffe:3240:800:1005::2/64 為網(wǎng)卡eth0配置IPv6地址; ifconfig eth0 add 33ffe:3240:800:1005::2/64 為網(wǎng)卡eth0刪除IPv6地址; 練習(xí)的時(shí)候,ssh登陸linux服務(wù)器操作要小心,關(guān)閉了就不能開(kāi)啟了,除非你有多網(wǎng)卡。實(shí)例4:用ifconfig修改MAC地址 命令: ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE 輸出:[root@localhost ~]# ifconfig eth0 down //關(guān)閉網(wǎng)卡 [root@localhost ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址 [root@localhost ~]# ifconfig eth0 up //啟動(dòng)網(wǎng)卡 [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:68 errors:0 dropped:0 overruns:0 frame:0TX packets:68 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB) [root@localhost ~]# ifconfig eth0 hw ether 00:50:56:BF:26:20 //關(guān)閉網(wǎng)卡并修改MAC地址 [root@localhost ~]# ifconfig eth0 up //啟動(dòng)網(wǎng)卡 [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20 inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:68 errors:0 dropped:0 overruns:0 frame:0TX packets:68 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB) 說(shuō)明:實(shí)例5:配置IP地址 命令:輸出:[root@localhost ~]# ifconfig eth0 192.168.120.56 [root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 [root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255說(shuō)明: ifconfig eth0 192.168.120.56 給eth0網(wǎng)卡配置IP地:192.168.120.56 ifconfig eth0 192.168.120.56 netmask 255.255.255.0 給eth0網(wǎng)卡配置IP地址:192.168.120.56 ,并加上子掩碼:255.255.255.0 ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255 /給eth0網(wǎng)卡配置IP地址:192.168.120.56,加上子掩碼:255.255.255.0,加上個(gè)廣播地址: 192.168.120.255實(shí)例6:?jiǎn)⒂煤完P(guān)閉ARP協(xié)議 命令: ifconfig eth0 arp ifconfig eth0 -arp 輸出:[root@localhost ~]# ifconfig eth0 arp [root@localhost ~]# ifconfig eth0 -arp說(shuō)明: ifconfig eth0 arp 開(kāi)啟網(wǎng)卡eth0 的arp協(xié)議; ifconfig eth0 -arp 關(guān)閉網(wǎng)卡eth0 的arp協(xié)議;實(shí)例7:設(shè)置最大傳輸單元 命令: ifconfig eth0 mtu 1500 輸出:[root@localhost ~]# ifconfig eth0 mtu 1480 [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1480 Metric:1RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:597062089 (569.4 MiB) TX bytes:2643973 (2.5 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:9973 errors:0 dropped:0 overruns:0 frame:0TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)[root@localhost ~]# ifconfig eth0 mtu 1500 [root@localhost ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000 RX bytes:597072333 (569.4 MiB) TX bytes:2650581 (2.5 MiB)lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0UP LOOPBACK RUNNING MTU:16436 Metric:1RX packets:9973 errors:0 dropped:0 overruns:0 frame:0TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0 RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)[root@localhost ~]# 說(shuō)明: 設(shè)置能通過(guò)的最大數(shù)據(jù)包大小為 1500 bytes備注:用ifconfig命令配置的網(wǎng)卡信息,在網(wǎng)卡重啟后機(jī)器重啟后,配置就不存在。要想將上述的配置信息永遠(yuǎn)的存的電腦里,那就要修改網(wǎng)卡的配置文件了。
讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶,將通過(guò)不懈努力成為客戶在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、網(wǎng)絡(luò)空間、營(yíng)銷軟件、網(wǎng)站建設(shè)、修水網(wǎng)站維護(hù)、網(wǎng)站推廣。
linux中有沒(méi)有函數(shù)可以得到子網(wǎng)掩碼地址
Ifconfig命令(注意:此方法配置的ip地址后計(jì)算機(jī)從新啟動(dòng)將會(huì)失效。) 使用ifconfig命令配置網(wǎng)卡的ip地址。此命令通常用來(lái)零時(shí)的測(cè)試用,計(jì)算機(jī)啟動(dòng)后,ip地址的配置將自動(dòng)失效。具體用法如下:ethx中的x代表第幾快以太網(wǎng)卡,默認(rèn)第一塊為0;ipaddr代表ip地址;x.x.x.x為子網(wǎng)掩碼。 例如給網(wǎng)卡eth0配置的ip地址為192.168.1.1 子網(wǎng)掩碼為 255.255.255.0 。 如下下圖所示:永久方法如下: 編輯文件vi /etc/sysconfig/network-scripts/ifcfg-ethx配置完以后重啟動(dòng)服務(wù),ip地址就配置好了。
如何用linux命令修改linux主機(jī)ip網(wǎng)關(guān)子網(wǎng)掩碼
linux一般使用ifconfig命令修改linux主機(jī)的ip、網(wǎng)關(guān)或子網(wǎng)掩碼。
1.命令格式:
ifconfig [網(wǎng)絡(luò)設(shè)備] [參數(shù)]
2.命令功能:
ifconfig 命令用來(lái)查看和配置網(wǎng)絡(luò)設(shè)備。當(dāng)網(wǎng)絡(luò)環(huán)境發(fā)生改變時(shí)可通過(guò)此命令對(duì)網(wǎng)絡(luò)進(jìn)行相應(yīng)的配置。
3.命令參數(shù):
up 啟動(dòng)指定網(wǎng)絡(luò)設(shè)備/網(wǎng)卡。
down 關(guān)閉指定網(wǎng)絡(luò)設(shè)備/網(wǎng)卡。該參數(shù)可以有效地阻止通過(guò)指定接口的IP信息流,如果想永久地關(guān)閉一個(gè)接口,我們還需要從核心路由表中將該接口的路由信息全部刪除。
arp 設(shè)置指定網(wǎng)卡是否支持ARP協(xié)議。
-promisc 設(shè)置是否支持網(wǎng)卡的promiscuous模式,如果選擇此參數(shù),網(wǎng)卡將接收網(wǎng)絡(luò)中發(fā)給它所有的數(shù)據(jù)包
-allmulti 設(shè)置是否支持多播模式,如果選擇此參數(shù),網(wǎng)卡將接收網(wǎng)絡(luò)中所有的多播數(shù)據(jù)包
-a 顯示全部接口信息
-s 顯示摘要信息(類似于 netstat -i)
add 給指定網(wǎng)卡配置IPv6地址
del 刪除指定網(wǎng)卡的IPv6地址
硬件地址 配置網(wǎng)卡最大的傳輸單元
mtu字節(jié)數(shù) 設(shè)置網(wǎng)卡的最大傳輸單元 (bytes)
netmask子網(wǎng)掩碼 設(shè)置網(wǎng)卡的子網(wǎng)掩碼。掩碼可以是有前綴0x的32位十六進(jìn)制數(shù),也可以是用點(diǎn)分開(kāi)的4個(gè)十進(jìn)制數(shù)。如果不打算將網(wǎng)絡(luò)分成子網(wǎng),可以不管這一選項(xiàng);如果要使用子網(wǎng),那么請(qǐng)記住,網(wǎng)絡(luò)中每一個(gè)系統(tǒng)必須有相同子網(wǎng)掩碼。
tunel 建立隧道
dstaddr 設(shè)定一個(gè)遠(yuǎn)端地址,建立點(diǎn)對(duì)點(diǎn)通信
-broadcast地址 為指定網(wǎng)卡設(shè)置廣播協(xié)議
-pointtopoint地址 為網(wǎng)卡設(shè)置點(diǎn)對(duì)點(diǎn)通訊協(xié)議
multicast 為網(wǎng)卡設(shè)置組播標(biāo)志
address 為網(wǎng)卡設(shè)置IPv4地址
txqueuelen長(zhǎng)度 為網(wǎng)卡設(shè)置傳輸列隊(duì)的長(zhǎng)度
4.使用實(shí)例:
實(shí)例1:顯示網(wǎng)絡(luò)設(shè)備信息(激活狀態(tài)的)
命令:
ifconfig
輸出:
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
說(shuō)明:
eth0 表示第一塊網(wǎng)卡, 其中 HWaddr 表示網(wǎng)卡的物理地址,可以看到目前這個(gè)網(wǎng)卡的物理地址(MAC地址)是 00:50:56:BF:26:20
inet addr 用來(lái)表示網(wǎng)卡的IP地址,此網(wǎng)卡的 IP地址是 192.168.120.204,廣播地址, Bcast:192.168.120.255,掩碼地址Mask:255.255.255.0
lo 是表示主機(jī)的回壞地址,這個(gè)一般是用來(lái)測(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ī)或用戶無(wú)從知道。
第一行:連接類型:Ethernet(以太網(wǎng))HWaddr(硬件mac地址)
第二行:網(wǎng)卡的IP地址、子網(wǎng)、掩碼
第三行:UP(代表網(wǎng)卡開(kāi)啟狀態(tài))RUNNING(代表網(wǎng)卡的網(wǎng)線被接上)MULTICAST(支持組播)MTU:1500(最大傳輸單元):1500字節(jié)
第四、五行:接收、發(fā)送數(shù)據(jù)包情況統(tǒng)計(jì)
第七行:接收、發(fā)送數(shù)據(jù)字節(jié)數(shù)統(tǒng)計(jì)信息。
實(shí)例2:?jiǎn)?dòng)關(guān)閉指定網(wǎng)卡
命令:
ifconfig eth0 up
ifconfig eth0 down
輸出:
說(shuō)明:
ifconfig eth0 up 為啟動(dòng)網(wǎng)卡eth0 ;ifconfig eth0 down 為關(guān)閉網(wǎng)卡eth0。ssh登陸linux服務(wù)器操作要小心,關(guān)閉了就不能開(kāi)啟了,除非你有多網(wǎng)卡。
實(shí)例3:為網(wǎng)卡配置和刪除IPv6地址
命令:
ifconfig eth0 add 33ffe:3240:800:1005::2/64
ifconfig eth0 del 33ffe:3240:800:1005::2/64
輸出:
說(shuō)明:
ifconfig eth0 add 33ffe:3240:800:1005::2/64 為網(wǎng)卡eth0配置IPv6地址;
ifconfig eth0 add 33ffe:3240:800:1005::2/64 為網(wǎng)卡eth0刪除IPv6地址;
練習(xí)的時(shí)候,ssh登陸linux服務(wù)器操作要小心,關(guān)閉了就不能開(kāi)啟了,除非你有多網(wǎng)卡。
實(shí)例4:用ifconfig修改MAC地址
命令:
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
輸出:
[root@localhost ~]# ifconfig eth0 down //關(guān)閉網(wǎng)卡
[root@localhost ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
[root@localhost ~]# ifconfig eth0 up //啟動(dòng)網(wǎng)卡
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:AA:BB:CC:DD:EE
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
[root@localhost ~]# ifconfig eth0 hw ether 00:50:56:BF:26:20 //關(guān)閉網(wǎng)卡并修改MAC地址
[root@localhost ~]# ifconfig eth0 up //啟動(dòng)網(wǎng)卡
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:20
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
說(shuō)明:
實(shí)例5:配置IP地址
命令:
輸出:
[root@localhost ~]# ifconfig eth0 192.168.120.56
[root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
說(shuō)明:
ifconfig eth0 192.168.120.56
給eth0網(wǎng)卡配置IP地:192.168.120.56
ifconfig eth0 192.168.120.56 netmask 255.255.255.0
給eth0網(wǎng)卡配置IP地址:192.168.120.56 ,并加上子掩碼:255.255.255.0
ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
/給eth0網(wǎng)卡配置IP地址:192.168.120.56,加上子掩碼:255.255.255.0,加上個(gè)廣播地址: 192.168.120.255
實(shí)例6:?jiǎn)⒂煤完P(guān)閉ARP協(xié)議
命令:
ifconfig eth0 arp
ifconfig eth0 -arp
輸出:
[root@localhost ~]# ifconfig eth0 arp
[root@localhost ~]# ifconfig eth0 -arp
說(shuō)明:
ifconfig eth0 arp 開(kāi)啟網(wǎng)卡eth0 的arp協(xié)議;
ifconfig eth0 -arp 關(guān)閉網(wǎng)卡eth0 的arp協(xié)議;
實(shí)例7:設(shè)置最大傳輸單元
命令:
ifconfig eth0 mtu 1500
輸出:
[root@localhost ~]# ifconfig eth0 mtu 1480
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F
inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1480 Metric:1
RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0
TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:597062089 (569.4 MiB) TX bytes:2643973 (2.5 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:9973 errors:0 dropped:0 overruns:0 frame:0
TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)
[root@localhost ~]# ifconfig eth0 mtu 1500
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:50:56:BF:26:1F
inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0
TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:597072333 (569.4 MiB) TX bytes:2650581 (2.5 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:9973 errors:0 dropped:0 overruns:0 frame:0
TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)
[root@localhost ~]#
說(shuō)明:
設(shè)置能通過(guò)的最大數(shù)據(jù)包大小為 1500 bytes
備注:用ifconfig命令配置的網(wǎng)卡信息,在網(wǎng)卡重啟后機(jī)器重啟后,配置就不存在。要想將上述的配置信息永遠(yuǎn)的存的電腦里,那就要修改網(wǎng)卡的配置文件了。
Linux配置網(wǎng)絡(luò)參數(shù)之IP地址、子網(wǎng)掩碼、網(wǎng)關(guān)地址,DNS
修改網(wǎng)卡命令規(guī)則 (eth0、eth1、eth2……)
打開(kāi)grub內(nèi)核引導(dǎo)程序,在……quiet 后面添加:
讓網(wǎng)卡命名規(guī)則生效
nmcli命令刪除錯(cuò)誤網(wǎng)卡命名
nmcli命令添加網(wǎng)卡命名
解析: nmcli connection 添加 類型 以太網(wǎng)設(shè)備 網(wǎng)卡設(shè)備名為eth0 nmcli命令的命名為eth0
修改IP地址、子網(wǎng)掩碼、網(wǎng)關(guān)地址、DNS
解析:nmcli connection 修改 網(wǎng)卡名 ipv4.方法 手工配置 ipv4.地址192.168.4.7/24 ipv4.網(wǎng)關(guān) 192.168.4.254 每次開(kāi)機(jī)自動(dòng)啟用以上所有參數(shù)
查看網(wǎng)卡配置文件
查看網(wǎng)關(guān)地址信息
Linux中,怎樣永久修改IP和子網(wǎng)掩碼
linux中永久修改ip和子網(wǎng)掩碼,可以用命令也可以直接到文件里修改。這里推薦直接到文件中修改。
1、進(jìn)入網(wǎng)卡配置文件 vi /etc/sysconfig/network-scripts/ifcfg-ethN (ifcfg-ethN是你要修改的網(wǎng)卡,可以用ifconfig查看你要修改的網(wǎng)卡)
2、進(jìn)入文件進(jìn)行編輯,更改其中的ip 和子網(wǎng)掩碼。
3、重啟網(wǎng)路服務(wù),并用ifconfig 查看網(wǎng)卡信息。
service network restart
ifconfig
網(wǎng)頁(yè)名稱:linux子網(wǎng)掩碼命令 linux查看子網(wǎng)掩碼的命令
地址分享:http://www.dlmjj.cn/article/dodgpih.html