日期:2014-05-16  浏览次数:20729 次

我使用过的Linux命令之ifconfig - 网络配置命令

我使用过的Linux命令之ifconfig - 网络配置命令

本文链接: http://codingstandards.iteye.com/blog/1130135? (转载请注明出处)

?

用途说明

ifconfig命令常用来显示系统中的网络接口(网卡)信息,也可以用来配置网络接口(configure a network interface),如激活、关闭、设置地址等。在Linux系统中,网卡命名规律:eth0为第一块以太网卡(Ethernet Card),eth1为第二块。lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位。

?

常用参数

格式:ifconfig

显示当前激活的网络接口信息。
If no arguments are given, ifconfig displays the status of the currently active interfaces.?

?

格式:ifconfig {INTERFACE}

显示指定网络接口的信息。比如:eth0, eth1。

If a single interface? argument? is given, it displays the status of the given interface only;

?

格式:ifconfig -a

显示所有网络接口的信息,无论是否激活。

if a single -a argument is given, it displays the status of all interfaces, even those that are down.?

Display info on all network interfaces on server, active or inactive.

?

其他格式,用来配置网络接口。

Otherwise, it configures an interface.

?

格式:ifconfig {INTERFACE} up

格式:ifup {INTERFACE}

激活指定网络接口。比如:eth0, eth1。

This? flag? causes the interface to be activated.? It is implicitly specified if an address is assigned to the interface.

?

格式:ifconfig {INTERFACE} down

格式:ifdown {INTERFACE}

关闭指定网络接口。

This flag causes the driver for this interface to be shut? down.

格式:ifconfig {INTERFACE} {IP}

格式:ifconfig {INTERFACE} {IP} netmask {NETMASK}

为指定网络接口设置IP地址和掩码,并自动激活。比如:eth0, eth0:0, eth0:1,后两个为虚拟网卡。

?

格式:ifconfig {INTERFACE} add {IP}

格式:ifconfig {INTERFACE}:0 {IP}

为指定网络接口添加IP地址。

?

格式:ifconfig {INTERFACE} del {IP}

为指定网络接口删除IP地址。

?

使用示例

示例一 通过ifconfig命令查看当前网络接口及状态

ifconfig不带参数,只打印处于激活状态的网络接口。

[root@jfht ~]# ifconfig
eth0????? Link encap:Ethernet? HWaddr 00:1B:78:40:8C:20?
????????? inet addr:211.103.28.xx? Bcast:211.103.28.31? Mask:255.255.255.224
????????? inet6 addr: fe80::21b:78ff:fe40:8c20/64 Scope:Link
????????? UP BROADCAST RUNNING MULTICAST? MTU:1500? Metric:1
????????? RX packets:134856806 errors:0 dropped:0 overruns:0 frame:0
????????? TX packets:140723373 errors:0 dropped:0 overruns:0 carrier:0
????????? collisions:0 txqueuelen:1000
????????? RX bytes:1680519599 (1.5 GiB)? TX bytes:2804853589 (2.6 GiB)
????????? Interrupt:114 Memory:fa000000-fa012800

?

现在解释一下输出信息的含义:

eth0:网络接口
link encap:网络类型
HWaddr:网卡物理地址
Inet addr :IP地址
Bcast:广播地址
Mask:子网掩码
UP:正在使用的网络接口
RX packets,TX packets接收和传输的数据包个数
RX byte,TX byte表示接搜和传输的具体数目
Interrupt:终端信息
Base address:内存地址


eth1????? Link encap:Ethernet? HWaddr 00:1B:78:40:8C:22?
????????? inet addr:192.168.1.191? Bcast:192.168.1.255? Mask:255.255.255.0
????????? inet6 addr: fe80::21b:78ff:fe40:8c22/64 Scope:Link
????????? UP BROADCAST RUNNING MULTICAST? MTU:1500? Metric:1
????????? RX packets:29821173 errors:0 dropped:0 overruns:0 frame:0
????????? TX packets:28680326 errors:0 dropped:0 overruns:0 carrier:0
????????? collisions:0 txqueuelen:1000
????????? RX bytes:4264958692 (3.9 GiB)? TX bytes:427504706 (407.7 MiB)
????????? Interrupt:122 Memory:f8000000-f8012800

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:30263265 errors:0 dropped:0 overruns:0 frame:0
????????? TX packets:30263265 errors:0 dropped:0 overruns:0 carrier:0
????????? collisions:0 txqueuelen:0
????????? RX bytes:63016162 (60.0 MiB)? TX bytes:63016162 (60.0 MiB)

?