ifconfig 命令用于配置和显示 Linux 内核中网络接口的网络参数。用 ifconfig 命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。若想将上述的配置信息永久存储在电脑里,需要修改网卡的配置文件。
ifconfig(参数)
参数说明:
显示网络设备信息(激活状态的):
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:3E:00:1E:51
inet addr:10.160.7.81 Bcast:10.160.15.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3607197869 (3.3 GiB) TX bytes:6115042 (5.8 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:56103 errors:0 dropped:0 overruns:0 frame:0
TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5079451 (4.8 MiB) TX bytes:5079451 (4.8 MiB)
说明:
启动关闭指定网卡:
ifconfig eth0 up
ifconfig eth0 down
ifconfig eth0 up 为启动网卡 eth0,ifconfig eth0 down 为关闭网卡 eth0。SSH 登录 Linux 服务器操作要小心,关闭了就不能开启了,除非你有多个网卡。
为网卡配置和删除 IPv6 地址:
ifconfig eth0 add 33ffe:3240:800:1005::2/64 # 为网卡 eth0 配置 IPv6 地址
ifconfig eth0 del 33ffe:3240:800:1005::2/64 # 为网卡 eth0 删除 IPv6 地址
用 ifconfig 修改 MAC 地址:
ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE
配置 IP 地址:
[root@localhost ~]# ifconfig eth0 192.168.2.10
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
启用和关闭 ARP 协议:
ifconfig eth0 arp # 开启网卡 eth0 的 ARP 协议
ifconfig eth0 -arp # 关闭网卡 eth0 的 ARP 协议
设置最大传输单元:
ifconfig eth0 mtu 1500 # 设置能通过的最大数据包大小为 1500 bytes
其它实例:
ifconfig # 处于激活状态的网络接口
ifconfig -a # 所有配置的网络接口,不论其是否激活
ifconfig eth0 # 显示 eth0 的网卡信息