新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Linux自帶防火墻開啟IP白名單的的配置詳解
防火墻配置文件名稱/etc/sysconfig/iptables
Red Hat Enterprise Linux Server release 6.0開始默認(rèn)配置如下
[root@DMT-Oracle-server ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
--iptables文件配置,從上至下生效,參考如上默認(rèn)配置,如果去掉倒數(shù)第三、第二行關(guān)于REJECT的內(nèi)容后service iptables start,相當(dāng)于放開了所有權(quán)限,和沒有開啟防火墻的結(jié)果一樣
--默認(rèn)INPUT、OUTPUT、FORWARD都是ACCEPT的
--不添加規(guī)則,則對所有端口的數(shù)據(jù)來者不拒
[root@DMT-Oracle-server ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -s 192.168.128.118 --dport 1521 -j ACCEPT
-A INPUT -p tcp -s 192.168.131.0/24 --dport 1521 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
--以上配置表示放開IP192.168.128.118和網(wǎng)段192.168.131的訪問服務(wù)器1521端口,必須放在兩行REJECT之前
--通過命令iptables -L -n 查看設(shè)置是否生效
各個(gè)參數(shù)解釋,參考man iptables
-A, --append chain rule-specification,表示添加一條規(guī)則
-D, --delete chain rule-specification,表示刪除一條規(guī)則
-R, --replace chain rulenum rule-specification,表示修改一條規(guī)則
-p, --protocol protocol,表示使用什么協(xié)議,TCP還是UDP
-s, --source address[/mask][,...],表示來源的IP或網(wǎng)段
-j, --jump target,This specifies the target of the rule --后面接動(dòng)作,主要的動(dòng)作有接受(ACCEPT)、丟棄(DROP)、拒絕(REJECT)及記錄(LOG)
INPUT、OUTPUT、dport、sport的區(qū)別:
INPUT:進(jìn)入本機(jī)的規(guī)則
OUTPUT:本機(jī)出去的規(guī)則
dport:目的端口
sport:來源端口
例子1:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
這條INPUT規(guī)則可以這么描述:
1.這是一條從外部進(jìn)入內(nèi)部本地服務(wù)器的數(shù)據(jù)。
2.數(shù)據(jù)包的目的(dport)地址是22,就是要訪問我本地的22端口。
3.允許以上的數(shù)據(jù)行為通過。
例子2:
iptables -A INPUT -p tcp --sport 22 -j ACCEPT
這條INPUT規(guī)則可以這么描述:
1.這是一條從外部進(jìn)入內(nèi)部本地服務(wù)器的數(shù)據(jù)。
2.數(shù)據(jù)包的來源端口是(sport)22,就是對方的數(shù)據(jù)包是22端口發(fā)送過來的。
3.允許以上數(shù)據(jù)行為。
例子3:
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
這條OUTPUT規(guī)則可以這么描述:
1.這是一條從內(nèi)部出去的數(shù)據(jù)。
2.出去的目的(dport)端口是22。
3.允許以上數(shù)據(jù)行為。
例子4:
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
這條OUTPUT規(guī)則可以這么描述:
1.這是一條從內(nèi)部出去的數(shù)據(jù)。
2.數(shù)據(jù)包的來源端口是(sport)22,從本服務(wù)器的22端口發(fā)出數(shù)據(jù)。
3.允許以上數(shù)據(jù)行為。
收集白名單IP(也就是經(jīng)常連接數(shù)據(jù)庫的IP)的腳本
[root@DMT-Oracle-server ~]# cat /iso/scripts/netstat_37.sh
#!/bin/sh
date>>/iso/scripts/log/netstat37.log
netstat -apnT|grep DW |awk '{print $5}'|sort -u >>/iso/scripts/log/netstat37.log
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >>/iso/scripts/log/netstat37.log
#其中DW是OracleSID的部分關(guān)鍵字
#要加上-T否則太長的IP會(huì)統(tǒng)計(jì)不準(zhǔn)確 -T, --notrim stop trimming long addresses
cat /iso/scripts/log/netstat37.log|grep 192|grep -v 37:1521|grep -v ffff|awk -F ":" '{print $1}'
cat /iso/scripts/log/netstat37.log|grep 192|grep -v 37:1521 | awk -F ":" '{print $4}'|sort -u
分享標(biāo)題:Linux自帶防火墻開啟IP白名單的的配置詳解
本文路徑:http://ef60e0e.cn/article/pijcdi.html
Red Hat Enterprise Linux Server release 6.0開始默認(rèn)配置如下
[root@DMT-Oracle-server ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
--iptables文件配置,從上至下生效,參考如上默認(rèn)配置,如果去掉倒數(shù)第三、第二行關(guān)于REJECT的內(nèi)容后service iptables start,相當(dāng)于放開了所有權(quán)限,和沒有開啟防火墻的結(jié)果一樣
--默認(rèn)INPUT、OUTPUT、FORWARD都是ACCEPT的
--不添加規(guī)則,則對所有端口的數(shù)據(jù)來者不拒
[root@DMT-Oracle-server ~]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -s 192.168.128.118 --dport 1521 -j ACCEPT
-A INPUT -p tcp -s 192.168.131.0/24 --dport 1521 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
--以上配置表示放開IP192.168.128.118和網(wǎng)段192.168.131的訪問服務(wù)器1521端口,必須放在兩行REJECT之前
--通過命令iptables -L -n 查看設(shè)置是否生效
各個(gè)參數(shù)解釋,參考man iptables
-A, --append chain rule-specification,表示添加一條規(guī)則
-D, --delete chain rule-specification,表示刪除一條規(guī)則
-R, --replace chain rulenum rule-specification,表示修改一條規(guī)則
-p, --protocol protocol,表示使用什么協(xié)議,TCP還是UDP
-s, --source address[/mask][,...],表示來源的IP或網(wǎng)段
-j, --jump target,This specifies the target of the rule --后面接動(dòng)作,主要的動(dòng)作有接受(ACCEPT)、丟棄(DROP)、拒絕(REJECT)及記錄(LOG)
INPUT、OUTPUT、dport、sport的區(qū)別:
INPUT:進(jìn)入本機(jī)的規(guī)則
OUTPUT:本機(jī)出去的規(guī)則
dport:目的端口
sport:來源端口
例子1:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
這條INPUT規(guī)則可以這么描述:
1.這是一條從外部進(jìn)入內(nèi)部本地服務(wù)器的數(shù)據(jù)。
2.數(shù)據(jù)包的目的(dport)地址是22,就是要訪問我本地的22端口。
3.允許以上的數(shù)據(jù)行為通過。
例子2:
iptables -A INPUT -p tcp --sport 22 -j ACCEPT
這條INPUT規(guī)則可以這么描述:
1.這是一條從外部進(jìn)入內(nèi)部本地服務(wù)器的數(shù)據(jù)。
2.數(shù)據(jù)包的來源端口是(sport)22,就是對方的數(shù)據(jù)包是22端口發(fā)送過來的。
3.允許以上數(shù)據(jù)行為。
例子3:
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
這條OUTPUT規(guī)則可以這么描述:
1.這是一條從內(nèi)部出去的數(shù)據(jù)。
2.出去的目的(dport)端口是22。
3.允許以上數(shù)據(jù)行為。
例子4:
iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
這條OUTPUT規(guī)則可以這么描述:
1.這是一條從內(nèi)部出去的數(shù)據(jù)。
2.數(shù)據(jù)包的來源端口是(sport)22,從本服務(wù)器的22端口發(fā)出數(shù)據(jù)。
3.允許以上數(shù)據(jù)行為。
收集白名單IP(也就是經(jīng)常連接數(shù)據(jù)庫的IP)的腳本
[root@DMT-Oracle-server ~]# cat /iso/scripts/netstat_37.sh
#!/bin/sh
date>>/iso/scripts/log/netstat37.log
netstat -apnT|grep DW |awk '{print $5}'|sort -u >>/iso/scripts/log/netstat37.log
echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++" >>/iso/scripts/log/netstat37.log
#其中DW是OracleSID的部分關(guān)鍵字
#要加上-T否則太長的IP會(huì)統(tǒng)計(jì)不準(zhǔn)確 -T, --notrim stop trimming long addresses
cat /iso/scripts/log/netstat37.log|grep 192|grep -v 37:1521|grep -v ffff|awk -F ":" '{print $1}'
cat /iso/scripts/log/netstat37.log|grep 192|grep -v 37:1521 | awk -F ":" '{print $4}'|sort -u
分享標(biāo)題:Linux自帶防火墻開啟IP白名單的的配置詳解
本文路徑:http://ef60e0e.cn/article/pijcdi.html