关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

Linux ifconfig命令:显示或设置网络设备

发布时间:2022-11-09 12:35:50
1491984010112764.jpg

Linux ifconfig(英文全拼:network interfaces configuring)命令用于显示或设置Linux内核中网络接口的网络参数。

语法格式:ifconfig [参数]

常用参数:

add<地址>设置网络设备IPv6的IP地址
del<地址>删除网络设备IPv6的IP地址
down关闭指定的网络设备
up启动指定的网络设备
IP地址指定网络设备的IP地址

参数说明

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

参考实例

显示网络设备信息:

[root@bunian ~]# ifconfigeth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500        inet 172.17.0.12  netmask 255.255.240.0  broadcast 172.17.15.255        inet6 fe80::5054:ff:fe7f:b032  prefixlen 64  scopeid 0x20<link>        ether 52:54:00:7f:b0:32  txqueuelen 1000  (Ethernet)        RX packets 8261454  bytes 1055415894 (1006.5 MiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 7614067  bytes 1170666685 (1.0 GiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0lo: 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 1000  (Local Loopback)        RX packets 90  bytes 11225 (10.9 KiB)        RX errors 0  dropped 0  overruns 0  frame 0        TX packets 90  bytes 11225 (10.9 KiB)        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

启动关闭指定网卡:

[root@bunian ~]# ifconfig eth0 down[root@bunian ~]# ifconfig eth0 up

为网卡配置和删除IPv6地址:

[root@bunian ~]# ifconfig eth0 add 33ffe:3240:800:1005::2/64[root@bunian ~]# ifconfig eth0 del 33ffe:3240:800:1005::2/64

用ifconfig修改MAC地址:

[root@bunian ~]# ifconfig eth0 down[root@bunian ~]# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE[root@bunian ~]# ifconfig eth0 up[root@bunian ~]# ifconfig eth1 hw ether 00:1D:1C:1D:1E [root@bunian ~]# ifconfig eth1 up

配置IP地址:

[root@bunian ~]# ifconfig eth0 192.168.1.100  //给eth0网卡配置IP地址[root@bunian ~]# ifconfig eth0 192.168.1.100 netmask 255.255.255.0  // 给eth0网卡配置IP地址,并加上子掩码[root@bunian ~]# ifconfig eth0 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255  // 给eth0网卡配置IP地址,加上子掩码,加上个广播地址

启用和关闭ARP协议

[root@bunian ~]# ifconfig eth0 arp  //开启[root@bunian ~]# ifconfig eth0 -arp  //关闭

设置最大传输单元

[root@bunian ~]# ifconfig eth0 mtu 1500  //设置能通过的最大数据包大小为 1500 byte



/template/Home/8a/PC/Static