Operations 11 min read
Master CentOS 7 Network Configuration: ifconfig, ifup/ifdown, and Essential Commands
This guide walks through CentOS 7 network configuration, covering ifconfig parameters, using ifup/ifdown, essential configuration files, default interface settings, additional ip commands, and troubleshooting tips for virtual machine cloning issues in Linux environments.
Raymond Ops
Raymond Ops
1. ifconfig Network Parameters
ifconfig is used to manually start, view, and modify network interface parameters.
<code>[root@linux ~]# ifconfig {interface} {up|down} <== 观察与启动接口
[root@linux ~]# ifconfig interface {options} <== 设置与修改接口
参数:
Interface,网卡接口代号,包括 eth0、eth1、ppp0 等
Options,可以接的参数,包括如下:
Up或down,启动 (up) 或关闭 (down) 该网络接口(不涉及任何参数)
mtu,可以设置不同的 MTU 数值,例如MTU 1500 (单位为 byte)
netmask,就是子屏蔽网络
broadcast,就是广播地址
范例:
范例一:观察所有的网络接口(直接输入 ifconfig)
[root@linux ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0F:EA:A3:06:A2
inet addr:192.168.10.100 Bcast:192.168.10.255
Mask:255.255.255.0
inet6 addr: fe80::20f:eaff:fe73:682/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3439 errors:0 dropped:0 overruns:0 frame:0
TX packets:2735 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:646935 (631.7 KiB) TX bytes:562313 (549.1 KiB)
Interrupt:209 Memory:fb000000-0</code>eth0: network interface name (also lo for loopback). HWaddr: hardware (MAC) address. inet addr: IPv4 address; Bcast and Mask represent broadcast and netmask. inet6 addr: IPv6 address (not used here). RX: received packets, errors, dropped, etc. TX: transmitted packets, errors, dropped, etc. collisions: packet collision count. txqueuelen: length of the transmission queue. RX Bytes / TX Bytes: total bytes received and transmitted. Interrupt / Memory: hardware IRQ and memory address.
2. ifup and ifdown
To apply settings from configuration files under
/etc/sysconfig/network-scripts, use
ifupor
ifdown.
<code>[root@linux ~]# ifup {interface}
[root@linux ~]# ifdown {interface}
[root@linux ~]# ifup eth0</code>ifup/ifdown are simple scripts that read the corresponding ifcfg-ethX file and apply the settings. Ensure the configuration file exists; otherwise the command will fail. After modifying an interface with ifconfig , use ifconfig eth0 down to bring it down, because ifdown compares the current state with the ifcfg-eth0 file.
3. CentOS 7 Network Configuration Files
/etc/resolv.conf – DNS configuration file /etc/hosts – hostname to IP mapping /etc/sysconfig/network – global network interfaces and routing information (only the last gateway is effective) /etc/sysconfig/network-scripts/ifcfg- interface – per‑interface configuration
4. Default Network Interface Configuration File (CentOS 7)
<code>TYPE=Ethernet # 网卡类型:为以太网
PROXY_METHOD=none # 代理方式:关闭状态
BROWSER_ONLY=no # 只是浏览器:否
BOOTPROTO=dhcp # 网卡的引导协议:DHCP
DEFROUTE=yes # 默认路由:是
IPV4_FAILURE_FATAL=no
IPV6INIT=yes # IPV6是否自动初始化: 是
IPV6_AUTOCONF=yes # IPV6是否自动配置:是
IPV6_DEFROUTE=yes # IPV6是否可以为默认路由:是
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eno16777736
UUID=f47bde51-fa78-4f79-b68f-d5dd90cfc698
DEVICE=ens33
ONBOOT=no # 是否开机启动
HWADDR="00:0C:29:EB:90:72"</code>5. Additional Useful Commands
<code>ip [选项] 操作对象{link|addr|route...}
# ip addr show # Show IP information
# ip addr add 192.168.0.1/24 dev eth0 # Set IP address
# ip addr del 192.168.0.1/24 dev eth0 # Delete IP address
# ip link show # Show interface information
# ip link set eth0 up # Bring interface up
# ip link set eth0 down # Bring interface down
# ip link set eth0 promisc on # Enable promiscuous mode
# ip link set eth0 promisc offi # Disable promiscuous mode
# ip link set eth0 txqueuelen 1200 # Set queue length
# ip link set eth0 mtu 1400 # Set MTU
# ip route show 或 ip route list 或 route -n # Show routing table
# ip route add 192.168.4.0/24 via 192.168.0.254 dev eth0 # Add route
# ip route add default via 192.168.0.254 dev eth0 # Set default gateway
# ip route del 192.168.4.0/24 # Delete route
# ip route del default # Delete default route</code>6. Summary
Cloned virtual machines often encounter network issues due to MAC address changes. Check the new MAC in the VM's network adapter settings, update the HWADDR field in the configuration file under /etc/sysconfig/network-scripts/ , and restart the network with systemctl start network . If problems persist, verify or delete the MAC entry in /etc/udev/rules.d/70-persistent-ipoib.rules .
Written by
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
0 followers
Reader feedback
How this landed with the community
Rate this article
Was this worth your time?
Discussion
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.