1. 网络配置概述
欧拉操作系统(openEuler)是华为开发的开源操作系统,其网络配置与管理方法与其他Linux发行版类似,但也有一些特定的特性。本文将详细介绍欧拉操作系统的网络配置与管理方法。更多学习教程www.fgedu.net.cn
# ip addr
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0:
link/ether 00:15:5d:00:01:02 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::215:5dff:fe00:102/64 scope link
valid_lft forever preferred_lft forever
2. 网络接口配置
网络接口是系统与网络连接的物理或逻辑通道,需要正确配置以确保网络通信正常。
# ip link show
1: lo:
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0:
link/ether 00:15:5d:00:01:02 brd ff:ff:ff:ff:ff:ff
# 启用网络接口
# ip link set eth0 up
# 禁用网络接口
# ip link set eth0 down
# 修改MTU大小
# ip link set eth0 mtu 1500
3. IP地址配置
IP地址是网络设备在网络中的唯一标识,需要正确配置以确保设备能够在网络中通信。学习交流加群风哥微信: itpux-com
# ip addr add 192.168.1.100/24 dev eth0
# 删除IP地址
# ip addr del 192.168.1.100/24 dev eth0
# 永久配置IP地址(使用NetworkManager)
# nmcli connection modify eth0 ipv4.method manual ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.dns “8.8.8.8,8.8.4.4”
# 激活连接
# nmcli connection up eth0
# 查看连接信息
# nmcli connection show eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
# 重启网络服务
# systemctl restart NetworkManager
4. DNS配置
DNS(域名系统)用于将域名解析为IP地址,是网络通信的重要组成部分。
# echo “nameserver 8.8.8.8” > /etc/resolv.conf
# 永久配置DNS服务器(使用nmcli)
# nmcli connection modify eth0 ipv4.dns “8.8.8.8,8.8.4.4”
# 激活连接
# nmcli connection up eth0
# 验证DNS配置
# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4
# nslookup www.baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
Name: www.baidu.com
Address: 110.242.68.3
Name: www.baidu.com
Address: 110.242.68.4
# 使用dig命令测试
# dig www.baidu.com
; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> www.baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53835
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;www.baidu.com. IN A
;; ANSWER SECTION:
www.baidu.com. 5 IN A 110.242.68.3
www.baidu.com. 5 IN A 110.242.68.4
;; Query time: 8 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Thu Apr 02 10:00:00 CST 2026
;; MSG SIZE rcvd: 74
5. 路由配置
路由配置决定了网络数据包的传输路径,是网络通信的重要组成部分。学习交流加群风哥QQ113257174
# ip route show
default via 192.168.1.1 dev eth0 proto static metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100 metric 100
# 添加静态路由
# ip route add 192.168.2.0/24 via 192.168.1.254 dev eth0
# 删除静态路由
# ip route del 192.168.2.0/24
# 添加默认路由
# ip route add default via 192.168.1.1 dev eth0
# vi /etc/sysconfig/network-scripts/route-eth0
192.168.2.0/24 via 192.168.1.254 dev eth0
# 重启网络服务
# systemctl restart NetworkManager
# 验证静态路由
# ip route show
6. 防火墙配置
防火墙用于保护系统免受网络攻击,需要正确配置以确保系统安全。
# systemctl status firewalld
# 启动防火墙
# systemctl start firewalld
# 停止防火墙
# systemctl stop firewalld
# 开机自启
# systemctl enable firewalld
# 禁止开机自启
# systemctl disable firewalld
# firewall-cmd –list-ports
# 开放端口
# firewall-cmd –zone=public –add-port=80/tcp –permanent
# 关闭端口
# firewall-cmd –zone=public –remove-port=80/tcp –permanent
# 重新加载配置
# firewall-cmd –reload
# 查看配置
# firewall-cmd –list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: ssh dhcpv6-client
ports: 80/tcp
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
7. 网络工具使用
欧拉操作系统提供了丰富的网络工具,用于网络配置、监控和故障排查。更多学习教程公众号风哥教程itpux_com
# ping -c 4 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.213 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.201 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.205 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.208 ms
— 192.168.1.1 ping statistics —
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.201/0.207/0.213/0.009 ms
# 跟踪路由
# traceroute 8.8.8.8
traceroute to 8.8.8.8 (8.8.8.8), 30 hops max, 60 byte packets
1 192.168.1.1 (192.168.1.1) 0.213 ms 0.201 ms 0.205 ms
2 10.0.0.1 (10.0.0.1) 1.234 ms 1.212 ms 1.198 ms
3 202.106.0.1 (202.106.0.1) 5.678 ms 5.654 ms 5.632 ms
4 202.106.1.1 (202.106.1.1) 10.123 ms 10.101 ms 10.089 ms
5 8.8.8.8 (8.8.8.8) 15.678 ms 15.654 ms 15.632 ms
# netstat -tuln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
udp 0 0 0.0.0.0:68 0.0.0.0:*
udp6 0 0 :::546 :::*
# 使用ss命令查看网络连接
# ss -tuln
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 *:22 *:*
tcp LISTEN 0 100 127.0.0.1:25 *:*
tcp LISTEN 0 128 :::22 :::*
tcp LISTEN 0 100 ::1:25 :::*
8. 网络监控
网络监控是确保网络正常运行的重要手段,需要定期检查网络状态和性能。
# sar -n DEV 1 5
Linux 5.10.0-60.18.0.50.oe2203.x86_64 (fgedu.net.cn) 04/02/2026 _x86_64_ (32 CPU)
10:00:00 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s %ifutil
10:00:01 AM eth0 123 102 12.3 8.5 0 0 0 0.1
10:00:02 AM eth0 145 121 15.2 10.1 0 0 0 0.2
10:00:03 AM eth0 132 110 13.5 9.2 0 0 0 0.1
10:00:04 AM eth0 118 98 11.2 7.8 0 0 0 0.1
10:00:05 AM eth0 130 105 12.8 8.9 0 0 0 0.1
Average: eth0 129 107 13.0 8.9 0 0 0 0.1
# iftop -i eth0
# 使用nload查看网络流量
# nload eth0
# 查看网络接口错误
# netstat -i
Kernel Interface table
Iface MTU RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
lo 65536 1234 0 0 0 1234 0 0 0 LRU
eth0 1500 12345 0 0 0 10987 0 0 0 BMRU
9. 网络故障排查
网络故障排查是系统管理员的重要技能,需要掌握基本的排查方法和工具。
# 1. 检查物理连接
# 2. 检查网络接口状态
# ip link show eth0
# 3. 检查IP地址配置
# ip addr show eth0
# 4. 检查路由配置
# ip route show
# 5. 检查DNS配置
# cat /etc/resolv.conf
# 6. 测试网络连通性
# ping 192.168.1.1
# 7. 测试DNS解析
# nslookup www.baidu.com
# 8. 检查防火墙配置
# firewall-cmd –list-all
# 1. 检查网络延迟
# ping -c 10 192.168.1.1
# 2. 检查网络带宽
# iperf3 -s
# iperf3 -c 192.168.1.100
# 3. 检查网络丢包
# mtr 192.168.1.1
# 4. 检查网络接口利用率
# sar -n DEV 1 10
10. 最佳实践
网络配置和管理的最佳实践可以提高系统的可靠性和安全性。author:www.itpux.com
– 使用静态IP地址配置,避免DHCP带来的IP地址变化
– 合理规划网络地址空间,避免IP地址冲突
– 配置合适的DNS服务器,确保域名解析正常
– 配置防火墙,只开放必要的端口
– 定期备份网络配置文件
– 定期监控网络状态和性能
– 建立网络故障应急预案
# 备份网络配置文件
# cp -r /etc/sysconfig/network-scripts/ /backup/network-config/
# 备份防火墙配置
# firewall-cmd –list-all > /backup/firewall-config.txt
# 备份NetworkManager配置
# cp -r /etc/NetworkManager/ /backup/NetworkManager/
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
