溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

iptable詳解

發布時間:2020-07-17 18:17:10 來源:網絡 閱讀:1405 作者:運維小當家 欄目:數據庫

查看iptables狀態-重啟


iptables 所在目錄 /etc/sysconfig/iptables

service iptables status 查看iptables狀態
service iptables restart iptables服務重啟
service iptables stop iptables服務禁用


啟動iptables  

modprobe ip_tables  

關閉iptables(關閉命令要比啟動復雜)  

iptalbes -F  

iptables -X  

iptables -Z  

iptables -P INPUT ACCEPT  

iptables -P OUTPUT ACCEPT  

iptables -P FORWARD ACCEPT  

modprobe -r ip_tables  

依次執行以上命令即可關閉iptables,否則在執行modproble -r ip_tables時將會提示  FATAL: Module ip_tables is in use.
 
 
 
 iptables -L -n
 
 iptables -F 清除預設表filter中的所有規則鏈的規則
 iptables -X 清除預設表filter中使用者自定鏈中的規則
 
 
 iptables -L -n
 
 #拋棄所有不符合三種鏈規則的數據包
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP


#設置:本地進程 lo 的 INPUT 和 OUTPUT 鏈接 ; eth0的INPUT鏈
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -jACCEPT
iptables -A INPUT -i eth0 -m state --state NEW,INVALID -j LOG
iptables -A OUTPUT -o lo -j ACCEPT

#開放22端口ssh
 iptables -A INPUT -p tcp -i eth0 --dport ssh -j ACCEPT

#開放80端口web
iptables -A INPUT -p tcp -i eth0 --dport 80 -j ACCEPT

#開放21、20端口ftp
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
 
#開放其他一些端 口  
iptables -A INPUT -p tcp --dport 1935 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT

#同上,開放需要端口的出口
iptables -A OUTPUT -p tcp --sport 1935 -j ACCEPT
。。。。
。。。。
。。。。

# 如使用vsftpd 使用了pasv 方式,如 pasv_min_port=6000 mx=7000 pasv_enable=YES之類
 iptables -A INPUT -p tcp --dport 6000:7000 -j ACCEPT
 iptables -A OUTPUT -p TCP --sport 6000:7000 -j ACCEPT
# 2個都要設,只設第一個不能下載,只設第二個不能上傳



#限制 .37 可以連接哪些端 口,
 iptables -A INPUT -s 192.168.0.37 -p tcp --dport 21 -j ACCEPT
 iptables -A INPUT -s 192.168.0.37 -p tcp --dport 20 -j ACCEPT
 
 #注:因上方設置的iptables -A INPUT -p tcp --dport 20 -j ACCEPT  & iptables -A INPUT -p tcp --dport 21 -j ACCEPT
 #允許開放20.21到所有用戶
 #所以要刪除掉該規則
 iptables -D INPUT -p tcp --dport 20 -j ACCEPT
 iptables -D INPUT -p tcp --dport 21 -j ACCEPT
 
 
#允許loopback!(不然會導致DNS無法正常關閉等問題)

IPTABLES -A INPUT -i lo -p all -j ACCEPT (如果是INPUT DROP)

IPTABLES -A OUTPUT -o lo -p all -j ACCEPT(如果是OUTPUT DROP)
 
 
 
 #將以上規則保存到 文件 sudo 是不行的,需要root權限(沒有設過的話, sudo passwd root 輸入新的root密碼即可。 然后su )
 iptables-save > /etc/iptables.up.rules
 
 修改 /etc/network/interfaces 腳本自動應用這些規則(末行是添加的)

auto eth0
iface eth0 inet dhcp
pre-up iptables-restore <  /etc/iptables.up.rules
post-down iptables-save >/etc/iptables.up.rules #關機時,把當前iptables 儲存


附 vsftpd.conf 主要項
listen=YES
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
pasv_min_port=6000
pasv_max_port=7000
pasv_enable=YES
ls_recurse_enable=YES
local_umask=022
file_open_mode=0755

這個FTP只供于管理員進行管理及上傳工作,因此本地賬號權限較大,要注意。
在/etc/vsftpd.chroot_list 只放root及該賬號




代碼:

#刪除原來 iptables 里面已經有的規則
iptables -F
iptables -X

#拋棄所有不符合三種鏈規則的數據包
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

#設置:本地進程 lo 的 INPUT 和 OUTPUT 鏈接 ; eth2的INPUT鏈
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -i eth2 -m state --state ESTABLISHED,RELATED -jACCEPT
iptables -A INPUT -i eth2 -m state --state NEW,INVALID -j LOG
iptables -A OUTPUT -o lo -j ACCEPT

#對其他主要允許的端口的 OUTPUT設置:
# DNS
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 53 -jACCEPT
iptables -A OUTPUT -o eth2 -p UDP --sport 1024:65535 --dport 53 -jACCEPT

#HTTP
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 80 -jACCEPT

#HTTPS
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 443 -jACCEPT

#Email 接受 和發送
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 110 -jACCEPT
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 25 -jACCEPT

# FTP 數據和控制
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 20 -jACCEPT
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 21 -jACCEPT

#DHCP
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 68 -jACCEPT
iptables -A OUTPUT -o eth2 -p UDP --sport 1024:65535 --dport 68 -jACCEPT

#POP3S Email安全接收
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 995 -jACCEPT

#時間同步服務器 NTP
iptables -A OUTPUT -o eth2 -p TCP --sport 1024:65535 --dport 123 -jACCEPT

#拒絕 eth2 其他剩下的
iptables -A OUTPUT -o eth2 --match state --state NEW,INVALID -jLOG



最后是有關于iptables存儲的命令:

代碼:

iptables-save >/etc/iptables.up.rule # 存在你想存的地方


代碼:

iptables-restore </etc/iptables.up.rules #調用



因為iptables 在每次機器重新啟動以后,需要再次輸入或者調用,為了方便操作,使用

代碼:

sudo gedit /etc/network/interfaces



代碼:

auto ath0
    iface ath0 inet dhcp

后面加上

代碼:

pre-up iptables-restore </etc/iptables.up.rules #啟動自動調用已存儲的iptables


代碼:

post-down iptables-save >/etc/iptables.up.rule #關機時,把當前iptables 儲存


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女