最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

centos7防火墻如何設(shè)置只對(duì)部分端口號(hào)限源

 更新時(shí)間:2023年06月03日 10:52:53   作者:chenshiying007  
這篇文章主要介紹了centos7防火墻如何設(shè)置只對(duì)部分端口號(hào)限源問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

centos7防火墻設(shè)置只對(duì)部分端口號(hào)限源

項(xiàng)目上線一段時(shí)候,安全測(cè)評(píng)整改的需要,需對(duì)特定一些端口進(jìn)行限源。

其他端口不做限制

iptables與firewalld的區(qū)別

1),firewalld可以動(dòng)態(tài)修改單條規(guī)則,動(dòng)態(tài)管理規(guī)則集,允許更新規(guī)則而不破壞現(xiàn)有會(huì)話和連接。而iptables,在修改了規(guī)則后必須得全部刷新才可以生效;

2),firewalld使用區(qū)域和服務(wù)而不是鏈?zhǔn)揭?guī)則;

3),firewalld默認(rèn)是拒絕的,需要設(shè)置以后才能放行。而iptables默認(rèn)是允許的,需要拒絕的才去限制;

4),firewalld自身并不具備防火墻的功能,而是和iptables一樣需要通過內(nèi)核的netfilter來實(shí)現(xiàn)。也就是說,firewalld和iptables一樣,它們的作用都用于維護(hù)規(guī)則,而真正使用規(guī)則干活的是內(nèi)核的netfilter。只不過

  • firewalld和iptables的結(jié)果以及使用方法不一樣!
  • firewalld是iptables的一個(gè)封裝,可以讓你更容易地管理iptables規(guī)則。它并不是iptables的替代品,雖然iptables命令仍可用于firewalld,但建議firewalld時(shí)僅使用firewalld命令。

一、安裝iptable

1.關(guān)閉默認(rèn)的firewall防火墻

systemctl stop firewalld.service 關(guān)閉防火墻
systemctl disable firewalld.service 關(guān)閉開機(jī)啟動(dòng)

2.開啟iptables

yum install iptables (根據(jù)centOS7的版本和內(nèi)核,有些版本已經(jīng)裝過,可以跳過此命令)
yum install iptables-services

3.基本操作

查看防火墻狀態(tài)

查看防火墻狀態(tài)
service iptables status
停止防火墻
service iptables stop
啟動(dòng)防火墻
service iptables start
重啟防火墻
service iptables restart
永久關(guān)閉防火墻
chkconfig iptables off
永久關(guān)閉后重啟
chkconfig iptables on
開機(jī)自啟
systemctl enable iptables.service

二、設(shè)置規(guī)則

表示清空所有默認(rèn)規(guī)則。

iptables -F

設(shè)置指定IP訪問指定端口8075

1、添加規(guī)則:禁止所有IP訪問8075

iptables -I INPUT -p tcp --dport 8075 -j DROP

查看規(guī)則

iptables --line -nvL INPUT

添加規(guī)則:允許127.0.0.1訪問8075

iptables -I INPUT -s 127.0.0.1 -p tcp --dport 8075 -j ACCEPT

規(guī)則已經(jīng)添加,測(cè)試

telnet 具體ip 8075

保存規(guī)則

service iptables save

三、特定url限源

示例添加swagger-相關(guān)限制

iptables -I INPUT -p tcp -m string --string "swagger-" --algo bm -j DROP 
iptables -I INPUT -s 10.0.120.13 -p tcp -m string --string "swagger-" --algo bm -j ACCEPT 

查詢數(shù)據(jù)庫中的數(shù)據(jù)也可能包含"swagger-" 也會(huì)直接攔截,對(duì)數(shù)據(jù)庫等存儲(chǔ)也需要添加放行規(guī)則

開放源

iptables -I INPUT -s 某某ip -j ACCEPT

iptables 導(dǎo)入導(dǎo)出

導(dǎo)出
iptables-save > iptables_bak
導(dǎo)入
iptables-restore <  iptables_bak

iptables 設(shè)置特定IP訪問指定端口

一、添加規(guī)則

設(shè)置禁止所有IP訪問指定端口8075

[root@zabbix_server ~]# iptables -I INPUT -p tcp --dport 8075 -j DROP

二、測(cè)試telnet 

[root@zabbix_server ~]# telnet 127.0.0.1 8075
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection timed out

三、刪除規(guī)則

1、查詢規(guī)則編號(hào)

[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP 83 packets, 4016 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        8   408 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8075 
2     144M   15G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3     4037  214K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
4        3   156 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25601 
5     4085  218K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
6    22638 1169K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 
7     264K   14M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:9000 
8     443K   23M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10050 
9    76134 4093K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10051

可以看到禁止訪問8075的規(guī)則編號(hào)為1

2、刪除指定規(guī)則編號(hào)的規(guī)則

[root@zabbix_server ~]# iptables -D INPUT 1

再查詢

[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP 20 packets, 961 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     144M   15G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
2     4038  214K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
3        3   156 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25601 
4     4087  218K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
5    22644 1169K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 
6     264K   14M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:9000 
7     443K   23M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10050 
8    76156 4094K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10051 
9       44  2208 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dp

已經(jīng)刪除了,測(cè)試telnet

[root@zabbix_server ~]# telnet 127.0.0.1 8075
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

四、設(shè)置指定IP訪問指定端口8075

1、添加規(guī)則:禁止所有IP訪問8075

[root@zabbix_server ~]# iptables -I INPUT -p tcp --dport 8075 -j DROP
[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP 3 packets, 156 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8075 
2     145M   15G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3     4038  214K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
4        3   156 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25601 
5     4090  219K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
6    22650 1169K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 
7     264K   14M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:9000 
8     443K   23M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10050 
9    76183 4095K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10051 
10      44  2208 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3000 
11       7   284 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:5672 
12       2    80 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dp

2、添加規(guī)則:允許127.0.0.1訪問8075

[root@zabbix_server ~]# iptables -I INPUT -s 127.0.0.1 -p tcp --dport 8075 -j ACCEPT

3、查詢規(guī)則:

[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP 20 packets, 1004 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 ACCEPT     tcp  --  *      *       127.0.0.1            0.0.0.0/0           tcp dpt:8075 
2        0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8075 
3     145M   15G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
4     4039  214K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
5        3   156 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25601 
6     4096  219K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
7    22660 1170K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306 
8     264K   14M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:9000 
9     443K   23M ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:10050

規(guī)則已經(jīng)添加,測(cè)試

[root@zabbix_server ~]# telnet 127.0.0.1 8075
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

本機(jī)可以訪問8075,其他機(jī)器上不能訪問8075

[root@localhost etc]# telnet 172.28.18.75 8075
Trying 172.28.18.75...
telnet: connect to address 172.28.18.75: Connection timed out

4、允許172.28.18.71可以訪問8075,(172.28.18.71是需要訪問8075的服務(wù)器)

[root@zabbix_server ~]# iptables -I INPUT -s 172.28.18.71 -p tcp --dport 8075 -j ACCEPT

查看規(guī)則

[root@zabbix_server ~]# iptables --line -nvL INPUT
Chain INPUT (policy DROP 9 packets, 456 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 ACCEPT     tcp  --  *      *       172.28.18.71         0.0.0.0/0           tcp dpt:8075 
2        3   132 ACCEPT     tcp  --  *      *       127.0.0.1            0.0.0.0/0           tcp dpt:8075 
3        7   420 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp dpt:8075 
4     145M   15G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
5     4040  214K ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
6        3   156 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:25601 
7     4100  219K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:80 
8    22674 1171K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306

在172.28.18.71上測(cè)試telnet 8075

[root@localhost etc]# telnet 172.28.18.75 8075
Trying 172.28.18.75...
Connected to 172.28.18.75.
Escape character is '^]'.

訪問成功,保存規(guī)則

[root@zabbix_server ~]# service iptables save
iptables:將防火墻規(guī)則保存到 /etc/sysconfig/iptables:[確定]

重啟服務(wù)

[root@zabbix_server ~]# service iptables save
iptables:將防火墻規(guī)則保存到 /etc/sysconfig/iptables:[確定]
[root@zabbix_server ~]# service iptables restart
iptables:將鏈設(shè)置為政策 ACCEPT:filter [確定]
iptables:清除防火墻規(guī)則:[確定]
iptables:正在卸載模塊:[確定]
iptables:應(yīng)用防火墻規(guī)則:[確定]

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

台北市| 措美县| 普兰店市| 平顺县| 盐城市| 阜新市| 图木舒克市| 本溪| 枣阳市| 辽阳县| 鄂托克旗| 蓝山县| 六盘水市| 罗山县| 彭山县| 娱乐| 高密市| 龙里县| 孝昌县| 日土县| 台湾省| 香格里拉县| 新田县| 靖宇县| 大丰市| 晋宁县| 六安市| 吉林市| 北流市| 普安县| 龙陵县| 蓬溪县| 河源市| 密山市| 鹤岗市| 旅游| 东莞市| 基隆市| 启东市| 赤城县| 邛崃市|