我使用过的Linux命令之ifconfig 您所在的位置:网站首页 linux重启和关闭系统命令 我使用过的Linux命令之ifconfig

我使用过的Linux命令之ifconfig

2023-05-05 23:22| 来源: 网络整理| 查看: 265

 

用途说明

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不带参数,只打印处于激活状态的网络接口。

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)

ifconfig命令跟上-a参数,打印所有配置的网络接口,不论其是否激活。 

[root@jfht ~]# ifconfig -a 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:134856877 errors:0 dropped:0 overruns:0 frame:0 TX packets:140723396 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1680524793 (1.5 GiB) TX bytes:2804859207 (2.6 GiB) Interrupt:114 Memory:fa000000-fa012800 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:29821183 errors:0 dropped:0 overruns:0 frame:0 TX packets:28680336 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4264959332 (3.9 GiB) TX bytes:427505346 (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:30263271 errors:0 dropped:0 overruns:0 frame:0 TX packets:30263271 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:63016642 (60.0 MiB) TX bytes:63016642 (60.0 MiB) sit0 Link encap:IPv6-in-IPv4 NOARP MTU:1480 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:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

 

ifconfig命令跟上指定网络接口名称,就可以查看具体的网卡信息了。 

[root@jfht ~]# ifconfig eth1 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:29821190 errors:0 dropped:0 overruns:0 frame:0 TX packets:28680343 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4264959780 (3.9 GiB) TX bytes:427505794 (407.7 MiB) Interrupt:122 Memory:f8000000-f8012800 [root@jfht ~]#

 

示例二 在VMWare虚拟机中用ifconfig命令关闭和激活网卡

VMWare虚拟机,网络连接采用NAT方式,操作系统为RHEL3.4。从Windows的cmd窗口通过ping命令来确认。

 

开始时,eth0处于激活状态。

ping 192.168.227.128 

正在 Ping 192.168.227.128 具有 32 字节的数据: 来自 192.168.227.128 的回复: 字节=32 时间



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有