04.ifconfig命令

ifconfig命令用法

ifconfig作用:用来配置网络或显示当前网络接口状态。

 

网卡说明

ifconfig示例:

[root@localhost ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 216231  bytes 309989247 (295.6 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 46307  bytes 2845601 (2.7 MiB)

        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 1  (Local Loopback)

        RX packets 40  bytes 4564 (4.4 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 40  bytes 4564 (4.4 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

        ether 52:54:00:f4:c9:eb  txqueuelen 1000  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

[root@localhost ~]#

ens33

表示物理网卡。

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 216231  bytes 309989247 (295.6 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 46307  bytes 2845601 (2.7 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

第一行

UP,BROADCAST,RUNNING,MULTICAST中:

UP:表示网卡开启状态。

BROADCAST:表示支持广播。

RUNNING:表示网线处理连接状态。

MULTICAST:表示支持组播。

mtu 1500:表示最大传输单元大小为1500字节。

第二行

inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255中:

inet 192.168.234.129:表示IPV4网卡的IP地址。

netmask 255.255.255.0:表示IPV4网卡的子网掩码。

broadcast 192.168.234.255:表示IPV4网卡的广播地址。

第三行

inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>中:

inet6 fe80::ea7d:7dde:491b:3403:表示IPV6的IP地址。

prefixlen 64:表示IPV6的子网掩码

scopeid 0x20<link>

第四行

ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)中:

ether 00:0c:29:ff:ed:a6:表示连接类型为以太网。

txqueuelen 1000  (Ethernet):表示传输对列的长度为1000。

第五、六行

RX packets 216231  bytes 309989247 (295.6 MiB)

RX errors 0  dropped 0  overruns 0  frame 0

RX 中:

packets:表示接收数据包大小。

bytes:表示接收比特位大小。

errors:表示总的收包的错误数量。

dropped:表示接收数据包已经进入了 Ring Buffer数量。

 

第七、八行

TX packets 46307  bytes 2845601 (2.7 MiB)

TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

TX 中:

packets:表示发送数据包大小。

bytes:表示发送比特位大小。

errors:表示总的发包的错误数量。

dropped:表示发送数据包已经进入了 Ring Buffer数量。

lo

表示回环网卡。

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 1  (Local Loopback)

        RX packets 40  bytes 4564 (4.4 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 40  bytes 4564 (4.4 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0

表示虚拟网卡。

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255

        ether 52:54:00:f4:c9:eb  txqueuelen 1000  (Ethernet)

        RX packets 0  bytes 0 (0.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 0  bytes 0 (0.0 B)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ifconfig修改IP

说明:修改后当前终端会终断,需要重新使用新的IP地址进行连接

临时修改IP

ifconfig 网卡名 IP地址 netmask 子网掩码

直接修改网卡IP但是重启服务器之后IP失效。

 

查看网卡信息:

[root@localhost ~]# ifconfig ens33

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 717148  bytes 1024746295 (977.2 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 169346  bytes 10377095 (9.8 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

修改网卡信息

[root@localhost ~]# ifconfig ens33 83.16.16.134 netmask 255.255.255.0

 

查看网卡信息:

[root@localhost ~]# ifconfig ens33

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 83.16.16.134  netmask 255.255.255.0  broadcast 83.16.16.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 717284  bytes 1024756483 (977.2 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 169425  bytes 10386877 (9.9 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

systemctl restart network

centos7重启网卡:

[root@localhost ~]# systemctl restart network

 

service network restart

centos6重启网卡:

[root@localhost ~]# service network restart

Restarting network (via systemctl):                        [  OK  ]

 

添加临时IP

ifconfig 网卡名:网卡编号 IP地址 netmask 子网掩码

注:网卡编号可以自定义。

 

添加第一个临时IP:

[root@localhost ~]# ifconfig ens33:0 83.12.132.200 netmask 255.255.255.0

 

添加第二个临时IP:

[root@localhost ~]# ifconfig ens33:1 83.16.19.134 netmask 255.255.255.0

 

查看IP:

[root@localhost ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 717775  bytes 1024794903 (977.3 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 169747  bytes 10425128 (9.9 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 83.12.132.200  netmask 255.255.255.0  broadcast 83.12.132.255

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

 

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 83.16.19.134  netmask 255.255.255.0  broadcast 83.16.19.255

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

 

删除临时IP

ifconfig 网卡名:网卡编号 del IP地址

删除临时IP:

[root@localhost ~]# ifconfig ens33:0 del 83.12.132.200

 

查看IP

[root@localhost ~]# ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.234.129  netmask 255.255.255.0  broadcast 192.168.234.255

        inet6 fe80::ea7d:7dde:491b:3403  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

        RX packets 717933  bytes 1024806336 (977.3 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 169825  bytes 10435227 (9.9 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 83.16.19.134  netmask 255.255.255.0  broadcast 83.16.19.255

        ether 00:0c:29:ff:ed:a6  txqueuelen 1000  (Ethernet)

 

posted @ 2020-12-23 09:42  AI非AI  阅读(633)  评论(0)    收藏  举报