ifconfig
注解
ifconfig 是一个古老的工具,现在显得有些过时了。
更推荐使用 ip 命令 ,这是网络配置工具的集大成者。
ifconfig 不带任何参数即可查询当前所有已 启用 ( up )网卡的状态:
带上 -a
参数即查询所有网卡,包括 禁用 的( down ):
$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 08:00:27:aa:87:65
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:239850 errors:0 dropped:0 overruns:0 frame:0
TX packets:232433 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39353582 (39.3 MB) TX bytes:160813991 (160.8 MB)
eth1 Link encap:Ethernet HWaddr 08:00:27:af:9e:56
inet addr:192.168.56.11 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feaf:9e56/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:154411 errors:0 dropped:0 overruns:0 frame:0
TX packets:147333 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11788649 (11.7 MB) TX bytes:141396393 (141.3 MB)
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:96 errors:0 dropped:0 overruns:0 frame:0
RX bytes:8692 (8.6 KB) TX bytes:8692 (8.6 KB)
带上网卡名则查询指定网卡:
$ ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:aa:87:65
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:239850 errors:0 dropped:0 overruns:0 frame:0
TX packets:232433 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39353582 (39.3 MB) TX bytes:160813991 (160.8 MB)
启停
启用网卡 eth0
:
禁用网卡 eth0
:
$ ifconfig eth0 down
$ ifconfig eth0 promisc
关闭混杂模式:
配置
配置度量值( metric
):
配置 MTU :
$ ifconfig eth0 mtu 1500
配置 IP 地址以及掩码(可以分开):
小菜学编程