iptables 指定网卡_LINUX系统下的IPTABLES防火墙系统讲解(二)实战操作
iptables
數據流方向
iptables操作命令:
#iptables --help
Usage: iptables -[AD] chain rule-specification [options]
iptables -[RI] chain rulenum rule-specification [options]
iptables -D chain rulenum [options]
iptables -[LFZ] [chain] [options]
iptables -[NX] chain
iptables -E old-chain-name new-chain-name
iptables -P chain target [options]
iptables -h (print this help information)
--append -A chain 追加規則
--delete -D chain 刪除規則
--delete -D chain rulenum 刪除指定序號的規則
--insert -I chain [rulenum] 插入一條規則(default 1=first)
--replace -R chain rulenum 替換一條規則
--list -L [chain] 顯示出鏈或者鏈中的規則
--flush -F [chain] 在一個鏈或者所有鏈中清空規則
--zero -Z [chain] 清空計數
--new -N chain 創建用戶自定義鏈
--delete-chain
-X [chain] 刪除用戶自定義鏈
--policy -P chain target 指定默認規則
Change policy on chain to target
--rename-chain
-E old-chain new-chain
重命名用戶自定義鏈
Options:
--proto -p [!] proto 指定協議,!代表取反
--source -s [!] address[/mask] --指定源地址
source specification
--destination -d [!] address[/mask] --指定目標地址
destination specification
--in-interface -i [!] input name[+] --指定數據從哪個網口進來
network interface name ([+] for wildcard)
--jump -j target --匹配動作
target for rule (may load target extension)
--goto -g chain
jump to chain with no return
--match -m match --擴展匹配
extended match (may load extension)
--numeric -n --端口和IP以數值方式顯示,不作反解
--out-interface -o [!] output name[+] --指定數據從哪個網口出去
network interface name ([+] for wildcard)
--table -t table --指定使用哪個表 (default: `filter')
--verbose -v --顯示詳細信息
--line-numbers --顯示規則的序號
--exact -x expand numbers (display exact values)
傳輸層:協議(tcp/udp)
端口(sport/dport)
網絡層:
IP地址(sip/dip/icmp)
數據鏈路層:
mac地址(--mac-source)
物理層:
從哪個網卡進來 -i
從哪個網卡出去 -o
---------------
iptables
查看:
# iptables -t nat -L -n -v --line
# iptables -t filter -L -n
# iptables -t filter -L INPUT
# iptables -t filter -L INPUT -v -n
# iptables -t filter -L INPUT -n -v --line
# watch -n 0.1 iptables -L INPUT --line -n -v
追加規則:
# iptables -t filter -A INPUT -i lo -j ACCEPT
插入規則:
# iptables -t filter -I INPUT -i eth0 -j ACCEPT --插入成為第一條
# iptables -t filter -I INPUT 3 -i eth0 -j ACCEPT --插入成為第三條規則
替換規則:
# iptables -t filter -R INPUT 3 -i eth1 -j ACCEPT --替換成為指定規則
刪除規則:
# iptables -t filter -D INPUT 2 --刪除指定鏈指定編號的規則
+++++++++++
#iptables -t filter -A INPUT -i lo -j ACCEPT
#iptables -t filter -A OUTPUT -o lo -j ACCEPT
#iptables -t filter -A INPUT -i eth0 -s 192.168.0.0/24 -d 192.168.0.250 -j ACCEPT
# iptables -t filter -A INPUT -i eth1 -j ACCEPT
# iptables -L INPUT -n --line -v
# iptables -t filer -I INPUT 2 -i eth2 -j ACCEPT 插入默認第二條
# iptables -t filter -I INPUT -i eth3 -j ACCEPT 插入默認第一條
# iptables -t filter -R INPUT 1 -i eth4 -j ACCEPT 替換默認第一條
#iptables -t filter -D INPUT 1 刪除默認第一條
# iptables -t filter -F INPUT 清空filter所有INPUT鏈
#iptables -t filter -F
#iptables -L INPUT -n --line -v
+++++++++++++++++++
清空規則:
1、清空一張表
# iptables -t filter -F
2、清空一條鏈中的規則
# iptables -t filter -F INPUT
新建/刪除用戶自定義的鏈:
# iptables -t filter -N uplooking新建
# iptables -t filter -X uplooking 刪除
# iptables -t filter -X 清空filter表中所有用戶自定義鏈
+++++++++
iptables -t filter -N TCP
iptables -t filter -N UDP
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A INPUT -p tcp -j TCP
++++++++
更改默認規則:
# iptables -t filter -P INPUT ACCEPT
# iptables -t filter -P INPUT DROP
實例應用一(本機的訪問控制):
拒絕所有:允許本機能訪問所有服務,允許訪問DNS,postfix,dovecot,vsftpd,telnet,web,
iptables -t filter -P INPUT DROP
iptables -t filter -P OUTPUT DROP
1.允許本機訪問本機的所有服務:
[root@mail ~]# iptables -t filter -A INPUT -i lo -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o lo -j ACCEPT
+++++++++
iptables -t filter -A INPUT -p tcp -dport 5902 -i br0 -s 192.168.0.45 -j ACCEPT
iptables -t filter -A OUTPUT -o br0 -p tcp --sport 5902 -d 192.168.0.45 -j ACCEPT
iptables -L -n -v --line
iptables -t filter -A INPUT -i br0 -p tcp --dport 5900:5902 -s 192.168.0.0/24 -j ACCEPT
iptables -t filter -A OUTPUT -o br0 -p tcp --sport 5900:5902 -d 192.168.0.0/24 -j ACCEPT
++++++++++++++
2.允許指定客戶機訪問我的80端口
[root@mail ~]# iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -s 10.1.1.111 -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 80 -d 10.1.1.111 -j ACCEPT
[root@mail ~]# iptables -t filter -A INPUT -i eth0 -p tcp --dport 80 -s 10.1.1.0/24 -j ACCEPT
[root@mail ~]# iptables -t filter -A OUTPUT -o eth0 -p tcp --sport 80 -d 10.1.1.0/24 -j ACCEPT
[root@mail ~]# iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
[root@mail ~]# iptables -A OUTPUT -o eth0 -p tcp --sport 22 -j ACCEPT
# iptables -t filter -R INPUT 2 -p tcp -m multiport --dport 20:21,80,443,5900 -j ACCEPT
# iptables -t filter -R OUTPUT 2 -p tcp -m multiport --sport 20:21,80,443,5900 -j ACCEPT
[root@mail ~]# service iptables save --防火規則馬上寫馬上生效,但重啟機器或者重iptables服務,規則丟失.
將當前規則保存到 /etc/sysconfig/iptables: [確定]
從非默認位置恢復規則:
# iptables-save > /tmp/iptables.save
# iptables-restore < /tmp/iptables.save
icmp:
[root@mail ~]# iptables -t filter -i eth0 -A INPUT -p icmp -j ACCEPT
[root@mail ~]# iptables -t filter -o eth0 -A OUTPUT -p icmp -j ACCEPT
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的iptables 指定网卡_LINUX系统下的IPTABLES防火墙系统讲解(二)实战操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php怎样查看视频播放的进度条,H5中视
- 下一篇: linux 百度地图离线sdk,Andr