您好,登錄后才能下訂單哦!
查看iptables狀態(tài)-重啟
iptables 所在目錄 /etc/sysconfig/iptables
service iptables status 查看iptables狀態(tài)
service iptables restart iptables服務(wù)重啟
service iptables stop iptables服務(wù)禁用
啟動iptables
modprobe
ip_tables
關(guān)閉iptables(關(guān)閉命令要比啟動復(fù)雜)
iptalbes -F
iptables
-X
iptables -Z
iptables -P INPUT ACCEPT
iptables -P
OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
modprobe -r
ip_tables
依次執(zhí)行以上命令即可關(guān)閉iptables,否則在執(zhí)行modproble -r ip_tables時將會提示 FATAL:
Module ip_tables is in use.
iptables -L
-n
iptables -F 清除預(yù)設(shè)表filter中的所有規(guī)則鏈的規(guī)則
iptables -X
清除預(yù)設(shè)表filter中使用者自定鏈中的規(guī)則
iptables -L
-n
#拋棄所有不符合三種鏈規(guī)則的數(shù)據(jù)包
iptables -P INPUT DROP
iptables -P
OUTPUT DROP
iptables -P FORWARD DROP
#設(shè)置:本地進(jìn)程 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個都要設(shè),只設(shè)第一個不能下載,只設(shè)第二個不能上傳
#限制
.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
#注:因上方設(shè)置的iptables -A INPUT -p tcp --dport 20 -j
ACCEPT & iptables -A INPUT -p tcp --dport 21 -j
ACCEPT
#允許開放20.21到所有用戶
#所以要刪除掉該規(guī)則
iptables -D INPUT
-p tcp --dport 20 -j ACCEPT
iptables -D INPUT -p tcp --dport 21 -j
ACCEPT
#允許loopback!(不然會導(dǎo)致DNS無法正常關(guān)閉等問題)
IPTABLES -A
INPUT -i lo -p all -j ACCEPT (如果是INPUT DROP)
IPTABLES -A OUTPUT -o lo -p
all -j ACCEPT(如果是OUTPUT DROP)
#將以上規(guī)則保存到
文件 sudo 是不行的,需要root權(quán)限(沒有設(shè)過的話, sudo passwd root 輸入新的root密碼即可。 然后su )
iptables-save > /etc/iptables.up.rules
修改
/etc/network/interfaces 腳本自動應(yīng)用這些規(guī)則(末行是添加的)
auto eth0
iface eth0 inet
dhcp
pre-up iptables-restore < /etc/iptables.up.rules
post-down
iptables-save >/etc/iptables.up.rules #關(guān)機(jī)時,把當(dāng)前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只供于管理員進(jìn)行管理及上傳工作,因此本地賬號權(quán)限較大,要注意。
在/etc/vsftpd.chroot_list 只放root及該賬號
代碼:
#刪除原來 iptables 里面已經(jīng)有的規(guī)則
iptables -F
iptables -X
#拋棄所有不符合三種鏈規(guī)則的數(shù)據(jù)包
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
#設(shè)置:本地進(jìn)程 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設(shè)置:
# 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 接受 和發(fā)送
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 數(shù)據(jù)和控制
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
#時間同步服務(wù)器 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
最后是有關(guān)于iptables存儲的命令:
代碼:
iptables-save >/etc/iptables.up.rule # 存在你想存的地方
代碼:
iptables-restore </etc/iptables.up.rules #調(diào)用
因為iptables 在每次機(jī)器重新啟動以后,需要再次輸入或者調(diào)用,為了方便操作,使用
代碼:
sudo gedit /etc/network/interfaces
在
代碼:
auto ath0
iface ath0 inet dhcp
后面加上
代碼:
pre-up iptables-restore </etc/iptables.up.rules #啟動自動調(diào)用已存儲的iptables
代碼:
post-down iptables-save >/etc/iptables.up.rule #關(guān)機(jī)時,把當(dāng)前iptables 儲存
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。