【Linux】命令 - ifconfig

Posted by 西维蜀黍 on 2021-03-07, Last Modified on 2022-12-10

SYNOPSIS

$ ifconfig [-v] [-a] [-s] [interface]
$ ifconfig [-v] interface [aftype] options | address ...

Display

  • If no arguments are given, ifconfig displays the status of the currently active interfaces.
  • If a single interface argument is given, it displays the status of the given interface only;
  • if a single -a argument is given, it displays the status of all interfaces, even those that are down.
# display all interfaces which are currently available, even if down
$ ifconfig -a

# View network settings of an ethernet adapter:
$ ifconfig eth0

# be more verbose for some error conditions
$ ifconfi -v

Manage Network Interfaces

Disable/Enable Network Interfaces

# change the medium access control (MAC) address of an interface
$ ifconfig [interface_name] down/up
$ ifconfig eth0 up
$ ifconfig eth0 down

Setting

# Assign IP address to eth0 interface:
$ ifconfig eth0 192.168.1.56 
# 给eth0网卡配置IP地址,并加上子掩码
$ ifconfig eth0 192.168.1.56 netmask 255.255.255.0 
# 给eth0网卡配置IP地址,加上子掩码,加上个广播地址
$ ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255

# 配置和删除IPv6地址
# 为网卡eth0配置IPv6地址
$ ifconfig eth0 add 33ffe:3240:800:1005::2/64
# 为网卡eth0删除IPv6地址
$ ifconfig eth0 add 33ffe:3240:800:1005::2/64

# Set mac
$ ifconfig wlan0 hw ether 13:11:20:33:49:66

# 启用和关闭ARP协议
# 开启
$ ifconfig eth0 arp  
# 关闭
$ ifconfig eth0 -arp  

Reference