linux Network相关查看命令

ifconfig

ifconfig 是 Linux 内置的查看网络接口信息的工具。

ifconfig [网络接口]查看指定网络接口信息 ifconfig 后加上一个接口名,可查看特定接口的网络信息,而不是主机上的所有接口。

[root@master min]# ifconfig docker0

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

        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255

        ether 02:42:a5:b6:b7:a2  txqueuelen 0  (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)

 



ifconfig:查看所有已开启的网络接口。

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

        inet 172.17.0.1  netmask 255.255.0.0  broadcast 172.17.255.255

        ether 02:42:a5:b6:b7:a2  txqueuelen 0  (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

 

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

        inet 192.168.137.46  netmask 255.255.255.0  broadcast 192.168.137.255

        inet6 fe80::59d7:9049:c188:24ee  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:0d:85:3d  txqueuelen 1000  (Ethernet)

        RX packets 521  bytes 60140 (58.7 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 468  bytes 64273 (62.7 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 

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

        inet 192.168.2.138  netmask 255.255.255.0  broadcast 192.168.2.255

        inet6 fe80::ad95:dcc9:f9da:7581  prefixlen 64  scopeid 0x20<link>

        ether 00:0c:29:0d:85:47  txqueuelen 1000  (Ethernet)

        RX packets 110  bytes 16842 (16.4 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 77  bytes 8736 (8.5 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo 不是一个真正的网络接口,是一个特殊的模拟出来的网络接口,每个系统都有它,叫回环接口(loop)。其各个字段属性是固定的:

inet:127.0.0.1

netmask:255.0.0.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 1000  (Local Loopback)

        RX packets 48  bytes 4224 (4.1 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 48  bytes 4224 (4.1 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:78:35:b7  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

mtu:最大数据传送单元大小

inet:IPv4 地址(也就是我们常说的 IP 地址)

netmask:子网掩码

broadcast :广播地址

inet6:IPv6 地址(目前正在普及和应用)

RX:接收包的情况

TX:发送包的情况

collisions:数据传输发生冲突的次数

 ifconfig   -a 选项查看所有主机上的网络接口,包括未启动和未配置的接口。

ifconfig  -V 查看ifconfig 命令的版本信息
i
fconfig -s 查看统计信息
将网卡的 IP 地址设置为192.168.0.1:
ifconfig eth0 192.168.0.1 (格式: ifconfig 网络设备名 IP 地址)
暂时关闭或启用网卡:
关闭第一块网卡: ifconfig eth0 down
启用第一块网卡 ifconfig eth0 up
将网卡的子网掩码设置为 255.255.255.0:
ifconfig eth0 netmask 255.255.255.0 (格式:ifconfig 网络设备名 netmask子网掩码)
我们也可以同时设置 IP 地址和子网掩码:

ifconfig eth0 192.168.0.1 netmask 255.255.255.0

ifconfig 输出的状态信息

UP/DOWN

网卡是否启动了,如果是DOWN的话,那肯定无法用的;

RX packets

中的errors 包的数量如果过大说明网卡在接收时有问题;

TX packets

中的errors 包的数量如果过大说明网卡在发送时有问题;

如果发现某网络接口如 eth1 的 IP 地址等参数并未显示,可能是接口未开启,或接口未配置好。可以使用 ifconfig eth1 up 来开启。开启之后就能看到 IP 地址了,顺便一提,当前主机的 eth1 的 IP 地址是由网络中的 DHCP 服务器提供的。接下来,我们尝试使用 ifconfig 命令配置 eth1 的一些网络参数。

[root@centos ~]# ifconfig eth1 up # 开启 eth1 网络接口

[root@centos ~]# ifconfig eth1 192.168.16.125 netmask 255.255.255.0 # 修改 IP 地址

[root@centos ~]# ifconfig eth1 mtu 5000 # 修改 mtu

[root@centos ~]# ifconfig eth1 down # 关闭 eth1 网络接口

值得注意的是,ifconfig 改变的接口部分配置参数是临时的,如果系统重启或网络重启,这些改变的参数不会保留。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sky wide

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值