SUSE Linux 網路設定指南
在 SUSE Linux 系統中,網路管理是伺服器運行與維護的重要部分。本指南將介紹 SUSE Linux 的網路設定、網路監控與診斷工具,並提供一些進階操作技巧,包含 /etc/sysconfig/network
的相關設定。
目錄
查看網路介面資訊
-
使用
ip
指令(推薦)ip addr show ip link show
-
使用
ifconfig
(需安裝 net-tools)sudo zypper install net-tools -y ifconfig -a
-
使用
nmcli
(NetworkManager CLI)nmcli device status
-
使用
wicked
(SUSE 專用)sudo wicked ifstatus all sudo wicked show-config
配置 IP 地址
使用 ip
指令手動設定
sudo ip addr add 192.168.1.100/24 dev eth0
sudo ip link set eth0 up
# 移除 IP
sudo ip addr del 192.168.1.100/24 dev eth0
# 設定預設閘道
sudo ip route add default via 192.168.1.1
使用 nmcli
設定靜態 IP
sudo nmcli connection modify eth0 ipv4.addresses 192.168.1.100/24 ipv4.gateway 192.168.1.1 ipv4.method manual
sudo nmcli connection up eth0
使用 wicked
設定 DHCP
- 編輯
/etc/sysconfig/network/ifcfg-eth0
,設置:BOOTPROTO='dhcp' STARTMODE='auto'
- 啟動介面:
sudo wicked ifup eth0
網路診斷工具
-
ping
ping -c 4 google.com
-
traceroute
sudo zypper install traceroute -y traceroute google.com
-
ss(檢查連線狀態)
ss -tulnp
-
tcpdump(封包分析)
sudo zypper install tcpdump -y sudo tcpdump -i eth0
-
nmap(掃描開放埠)
sudo zypper install nmap -y sudo nmap -sS 192.168.1.0/24
防火牆與存取控制
使用 firewalld
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --list-all
使用 SuSEfirewall2(Legacy)
sudo systemctl enable --now SuSEfirewall2
sudo yast firewall set zone=EXT services_ext="http https" save
網路服務管理
使用 systemd-networkd
sudo systemctl enable --now systemd-networkd
networkctl status
DHCP 重新獲取 IP
sudo dhclient -r eth0
sudo dhclient eth0
設定及檢查主機名稱
hostnamectl status
sudo hostnamectl set-hostname my-suse-server
/etc/sysconfig/network 設定
在 SUSE 系統中,/etc/sysconfig/network/config
及 ifcfg-*
可用於全局網路設定:
# /etc/sysconfig/network/config
BOOTPROTO='dhcp' # 'none', 'bootp', 'dhcp'
STARTMODE='auto' # 'onboot', 'hotplug', 'manual'
GATEWAY='192.168.1.1'
NETCONFIG_DNS_STATIC_SERVERS='8.8.8.8 8.8.4.4'
# 若使用 DHCP,可在 ifcfg-eth0 中啟用
cat /etc/sysconfig/network/ifcfg-eth0
# 如:
# STARTMODE='auto'
# BOOTPROTO='dhcp'
- BOOTPROTO:指定取得 IP 的方式
- STARTMODE:介面啟動模式
- GATEWAY:預設閘道(靜態方式)
- DNS:可於
NETCONFIG_DNS_STATIC_SERVERS
指定多個 DNS
編輯後重啟網路服務:
sudo systemctl restart network
結語
本指南介紹了 SUSE Linux 中網路管理的基本與進階操作,包括介面資訊查詢、IP 設定、診斷工具、防火牆、服務管理以及 /etc/sysconfig/network
相關設定。透過這些步驟,您可以有效地管理 SUSE 伺服器的網路環境,確保系統的連線穩定與安全。