Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 網路介面與防火牆常用指令速查

編輯:Linux 教學

1. 開啟/關閉 TCP/UDP 埠口 (iptables)

# 開啟 81/tcp
iptables -I INPUT -i eth0 -p tcp --dport 81 -j ACCEPT
iptables -I OUTPUT -o eth0 -p tcp --sport 81 -j ACCEPT

# 關閉 81/tcp
iptables -I INPUT -i eth0 -p tcp --dport 81 -j DROP
iptables -I OUTPUT -o eth0 -p tcp --sport 81 -j DROP

2. 啟用/停用實體介面

# ifconfig 指令
ifconfig eth0 up
ifconfig eth0 down

# 或使用啟動腳本 (Red Hat 系列)
/sbin/ifup eth0
/sbin/ifdown eth0

3. 設定 IP 位址

臨時生效 (重開機失效)

ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255

永久生效 (修改設定檔)

編輯 /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.10
NETMASK=255.255.255.0
ONBOOT=yes

虛擬介面 (IP Alias)

建立 ifcfg-eth0:1、ifcfg-eth0:2… 同目錄下,設定不同 IPADDR。

套用變更

/etc/init.d/network restart
# 或
service network restart

小結

臨時測試用 ifconfig/iptables 即時生效;正式環境請修改 /etc/sysconfig/network-scripts/ 下對應檔案並重啟 network 服務。

Copyright © Windows教程網 All Rights Reserved