防火牆 iptables 封鎖或開放 IP

  1. Teamviewer, xrdp, tigervnc, Vino, freenx 都是很方便的遠方遙控軟體,但是在網路上的連線安全性堪憂。除了要選擇 ssl 加密連線的軟體之外,可以用iptables來開放特定IP連線至特定的port 封鎖其他的IP來補救:
# gedit /etc/sysconfig/iptables
  • 允許IP 1.2.3.4:

-A INPUT -p tcp --dport xxxxx -s 1.2.3.4 -j ACCEPT

  • 封鎖其他的IP:

-A INPUT -p tcp --dport xxxxx -j DROP

  • 允許IP 1.2.3.4 至1.2.3.9:

-A INPUT -p tcp -s iprange –src-range 1.2.3.4-1.2.3.9 –dport xxxxx -j ACCEPT

# service iptables restart

# service fail2ban restart

  1. 設定 sshd_config,除了port 22, 增列一個特定的 xxxxx

參考 http://www.placona.co.uk/172/linux/iptables-opening-server-ports-to-specific-ip-addresses/