CentOS ifconfig 配置详解

ifconfig 简介
ifconfig 是 Linux 系统中用于配置和显示网络接口信息的命令,通过 ifconfig 命令,用户可以查看网络接口的 IP 地址、子网掩码、广播地址、网关等信息,也可以修改网络接口的 IP 地址、子网掩码等配置。
ifconfig 命令基本语法
ifconfig [选项] 网络接口 [IP 地址]
ifconfig 命令常用选项
- a:显示所有网络接口的详细信息;
- -h:显示帮助信息;
- -s:仅显示网络接口的统计信息;
- -v:显示详细的版本信息;
- down:禁用指定的网络接口;
- up:启用指定的网络接口;
- address:指定网络接口的 IP 地址和子网掩码;
- netmask:指定网络接口的子网掩码;
- broadcast:指定网络接口的广播地址;
- mtu:指定网络接口的最大传输单元。
ifconfig 命令配置实例
查看所有网络接口信息
[root@centos ~]# ifconfig
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0

查看指定网络接口信息
[root@centos ~]# ifconfig eth0
eth0 Link encap:Ethernet Hardware Address:00:16:3E:XX:XX:XX
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0
配置网络接口 IP 地址
[root@centos ~]# ifconfig eth0 192.168.1.200 netmask 255.255.255.0
[root@centos ~]# ifconfig eth0
eth0 Link encap:Ethernet Hardware Address:00:16:3E:XX:XX:XX
inet addr:192.168.1.200 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0
禁用网络接口
[root@centos ~]# ifconfig eth0 down
启用网络接口
[root@centos ~]# ifconfig eth0 up

ifconfig 注意事项
- 在配置网络接口时,IP 地址、子网掩码等配置参数是否正确;
- 在修改网络接口配置后,确保网络连接正常;
- ifconfig 命令仅适用于 CentOS 6.x 版本,在 CentOS 7.x 及以上版本中,建议使用 ip 命令替代 ifconfig。
FAQs
Q1:ifconfig 命令在 CentOS 7.x 及以上版本中不适用,应该使用什么命令?
A1:在 CentOS 7.x 及以上版本中,可以使用 ip 命令替代 ifconfig,ip 命令具有更丰富的功能和更好的兼容性。
Q2:如何查看网络接口的 MTU 值?
A2:可以使用以下命令查看网络接口的 MTU 值:
[root@centos ~]# ifconfig eth0 | grep MTU
MTU:1500 Metric:1
【版权声明】:本站所有内容均来自网络,若无意侵犯到您的权利,请及时与我们联系将尽快删除相关内容!
发表回复