歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> linux iptables設置僅22、80端口可訪問

linux iptables設置僅22、80端口可訪問

日期:2017/3/1 14:55:58   编辑:關於Linux
linux iptables設置僅22、80端口可訪問 通過命令 netstat -tnl 可以查看當前服務器打開了哪些端口 Ssh代碼 netstat -tnl 查看防火牆設置 Ssh代碼 iptables -L -n 開放22、80端口 Ssh代碼 iptables -A INPUT -p tcp --dport 22 -j ACCEPT iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -p tcp --sport 80 -m state --state NEW,ESTABLISHED -j ACCEPT 取消其他端口的訪問規則 Ssh代碼 iptables -P INPUT DROP iptables -P FORWARD DROP iptables -P OUTPUT DROP 允許本地回環接口(即允許本機訪問本機) Ssh代碼 iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT 允許已建立的或相關連的通行(如數據庫鏈接) Ssh代碼 iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT 允許所有本機向外的訪問 Ssh代碼 iptables -A OUTPUT -j ACCEPT 保存配置: Ssh代碼 service iptables save
Copyright © Linux教程網 All Rights Reserved