龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

Linux ifconfig命令详解和使用示例(Linux网络参数配置和查看)(2)

时间:2014-05-19 02:37来源:网络整理 作者:网络 点击:
分享到:
代码如下: [root@localhost ~]# ifconfig eth0 down //关闭网卡 [root@localhost ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址 [root@localhost ~]# ifconfig eth0 up //启动网卡 [


代码如下:

[root@localhost ~]# ifconfig eth0 down //关闭网卡
[root@localhost ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
[root@localhost ~]# ifconfig eth0 up //启动网卡
[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)</p> <p>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 //关闭网卡并修改MAC地址
[root@localhost ~]# ifconfig eth0 up //启动网卡
[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)</p> <p>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)

实例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

说明:

ifconfig eth0 192.168.120.56 

给eth0网卡配置IP地:192.168.120.56

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 

给eth0网卡配置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网卡配置IP地址:192.168.120.56,加上子掩码:255.255.255.0,加上个广播地址: 192.168.120.255

实例6:启用和关闭ARP协议

命令:


代码如下:

ifconfig eth0 arp
ifconfig eth0 -arp

输出:


代码如下:

[root@localhost ~]# ifconfig eth0 arp
[root@localhost ~]# ifconfig eth0 -arp

说明:

ifconfig eth0 arp 开启网卡eth0 的arp协议;

ifconfig eth0 -arp 关闭网卡eth0 的arp协议;

实例7:设置最大传输单元

命令: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)</p> <p>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)</p> <p>[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)</p> <p>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)</p> <p>[root@localhost ~]#

说明:

设置能通过的最大数据包大小为 1500 bytes

精彩图集

赞助商链接