ifconfig(interfaces config)。通常需要以root身份登录或使用sudo来使用ifconfig工具

ifconfig 命令用来查看和配置网络设备。当网络环境发生改变时可通过此命令对网络进行相应的配置。

备注:用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。

ifconfig常见命令参数

1

2

3

4

5

6

7

8

9

10

11

12

13

14

Usage:

  ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]

  [add <address>[/<prefixlen>]]

  [del <address>[/<prefixlen>]]

  [[-]broadcast [<address>]]  [[-]pointopoint [<address>]]

  [netmask <address>]  [dstaddr <address>]  [tunnel <address>]

  [outfill <NN>] [keepalive <NN>]

  [hw <HW> <address>]  [metric <NN>]  [mtu <NN>]

  [[-]trailers]  [[-]arp]  [[-]allmulti]

  [multicast]  [[-]promisc]

  [mem_start <NN>]  [io_addr <NN>]  [irq <NN>]  [media <type>]

  [txqueuelen <NN>]

  [[-]dynamic]

  [up|down] ...

常用的命令展示

查看当前系统有几个网卡

1

[[email protected] ~]# ifconfig |grep eth* | awk -F '[ ]+' '{print $1}'

 

每天一个linux命令(27):ifconfig命令

启动关闭指定网卡

1

2

3

4

5

ifconfig eth0 up        # 启动 <br>ifcfg etho up           # 启动

ifconfig eth0 down      # 关闭<br>ifcfg eth0 down         # 关闭

ifconfig eth0 reload    # 重启

说明: ifconfig eth0 up 为启动网卡eth0 ;ifconfig eth0 down 为关闭网卡eth0。

       ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。

 

每天一个linux命令(27):ifconfig命令

为网卡配置和删除IPv6地址【临时生效,永久生效需要更改配置文件】

eth2网卡配置文件: /etc/sysconfig/network-scripts/ifcfg-eth2

1

2

3

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

 

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

为网卡配置和删除IPv4地址【临时生效,永久生效需要更改配置文件】

eth2网卡配置文件: /etc/sysconfig/network-scripts/ifcfg-eth2

1

[[email protected] ~]# ifconfig eth0 192.168.25.166 netmask 255.255.255.0 up

1

[[email protected] ~]# ifconfig eth0 192.168.25.166/24 up       【效果同上】

1

[[email protected] ~]# ip addr add 192.168.25.166/24  dev eth0  【效果同上】

 

每天一个linux命令(27):ifconfig命令

[[email protected] ~]# ifconfig eth0:ws 192.168.25.166 netmask 255.255.255.0 up

1

[[email protected] ~]# ifconfig eth0:ws 192.168.25.166/24 up       【效果同上】

1

[[email protected] ~]# ip addr add 192.168.25.166/24  dev eth0:ws  【效果同上】

 

每天一个linux命令(27):ifconfig命令

[[email protected] ~]#ifconfig eth0:ws  192.168.25.166 netmask 255.255.255.0 down

1

[[email protected] ~]#ifconfig eth0:ws  192.168.25.166/24 dwon     【效果同上】

1

[[email protected] ~]# ip addr del 192.168.25.166/24  dev eth0:ws  【效果同上】

 

每天一个linux命令(27):ifconfig命令

用ifconfig修改MAC地址

1

ifconfig eth0 down //关闭网卡

1

ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址

1

ifconfig eth0 up    //启动网卡

启用和关闭ARP协议

1

2

3

ifconfig eth0:ws arp

 

ifconfig eth0:ws -arp

设置最大传输单元

1

ifconfig eth0 mtu 1500

 

网卡配置文件

网卡eth2对应: /etc/sysconfig/network-scripts/ifcfg-eth2

网卡eth0对应: /etc/sysconfig/network-scripts/ifcfg-eth0

根据网卡名称找对应的文件名称即可

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

[[email protected] omd]# cat /etc/sysconfig/network-scripts/ifcfg-eth2

HWADDR=00:0c:29:E4:35:5D

TYPE=Ethernet

BOOTPROTO=none

IPADDR=192.168.25.133

PREFIX=24

GATEWAY=192.168.25.2

DNS1=192.168.25.2

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

IPV6INIT=no

NAME="eth2"

UUID=6e6f9829-0737-4943-ab21-61d6173ba8c4

ONBOOT=yes

LAST_CONNECT=1438160743

DEVICE=eth2

USERCTL=no

 

网卡的硬件信息

网卡出现乱序,多是因为Mac和网卡名称不一致导致,需要更改此网卡的硬件信息

1

2

3

4

5

6

7

8

9

10

11

12

[[email protected] ~]# cat /etc/udev/rules.d/70-persistent-net.rules

# This file was automatically generated by the /lib/udev/write_net_rules

# program, run by the persistent-net-generator.rules rules file.

#

# You can modify it, as long as you keep each rule on a single

# line, and change only the value of the NAME= key.

 

# PCI device 0x1022:0x2000 (vmxnet)

#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cc:16:f0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

 

# PCI device 0x1022:0x2000 (vmxnet)

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:e4:35:5d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

相关文章:

  • 2021-06-22
  • 2021-09-17
  • 2022-12-23
  • 2022-01-16
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-10-10
  • 2021-12-09
  • 2022-12-23
  • 2021-06-12
  • 2021-12-19
相关资源
相似解决方案