Linux ifconfig 命令 显示与设置网络设备

ifconfig 简述

  • Linux ifconfig 命令用于显示或设置网络设备。
  • ifconfig 可设置网络设备的状态,或是显示目前的设置。

语 法

ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<网络设备类型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]

参数说明

add<地址> 设置网络设备IPv6的IP地址。
del<地址> 删除网络设备IPv6的IP地址。
down 关闭指定的网络设备。
<hw<网络设备类型><硬件地址> 设置网络设备的类型与硬件地址。
io_addr<I/O地址> 设置网络设备的I/O地址。
irq<IRQ地址> 设置网络设备的IRQ。
media<网络媒介类型> 设置网络设备的媒介类型。
mem_start<内存地址> 设置网络设备在主内存所占用的起始地址。
metric<数目> 指定在计算数据包的转送次数时,所要加上的数目。
mtu<字节> 设置网络设备的MTU。
netmask<子网掩码> 设置网络设备的子网掩码。
tunnel<地址> 建立IPv4与IPv6之间的隧道通信地址。
up 启动指定的网络设备。
-broadcast<地址> 将要送往指定地址的数据包当成广播数据包来处理。
-pointopoint<地址> 与指定地址的网络设备建立直接连线,此模式具有保密功能。
-promisc 关闭或启动指定网络设备的promiscuous模式。
[IP地址] 指定网络设备的IP地址。
[网络设备] 指定网络设备的名称。

实 例

查看网络设备信息

  • eno16777736、lo 表示网卡的名字
[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.58.129  netmask 255.255.255.0  broadcast 192.168.58.255
        inet6 fe80::20c:29ff:feea:9e7f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ea:9e:7f  txqueuelen 1000  (Ethernet)
        RX packets 4340  bytes 300062 (293.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 944  bytes 143003 (139.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 40  bytes 15268 (14.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 15268 (14.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# 

启动关闭指定网卡

# ifconfig 网卡名 down
# ifconfig 网卡名 up
[root@localhost ~]# ifconfig lo down
[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.58.129  netmask 255.255.255.0  broadcast 192.168.58.255
        inet6 fe80::20c:29ff:feea:9e7f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ea:9e:7f  txqueuelen 1000  (Ethernet)
        RX packets 4522  bytes 313326 (305.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1015  bytes 152563 (148.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# ifconfig lo up
[root@localhost ~]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.58.129  netmask 255.255.255.0  broadcast 192.168.58.255
        inet6 fe80::20c:29ff:feea:9e7f  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ea:9e:7f  txqueuelen 1000  (Ethernet)
        RX packets 4547  bytes 315378 (307.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1029  bytes 154623 (150.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 40  bytes 15268 (14.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 15268 (14.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@localhost ~]# 

为网卡配置和删除IPv6地址

# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡诶之IPv6地址

# ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //为网卡删除IPv6地址

修改MAC地址

# ifconfig eth0 down //关闭eth0 网卡
# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
# ifconfig eth0 up //启动eth0 网卡
# ifconfig eth1 hw ether 00:1D:1C:1D:1E //关闭eth1 网卡并修改MAC地址 
# ifconfig eth1 up //启动eth1 网卡

配置IP地址

# 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
// 给eth0网卡配置IP地址,加上子网掩码,加上个广播地址

猜你喜欢

转载自blog.csdn.net/wangmx1993328/article/details/81563438