亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

centos7防火墻設(shè)置只對部分端口號限源

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

其他端口不做限制

iptables與firewalld的區(qū)別

1),firewalld可以動態(tài)修改單條規(guī)則,動態(tài)管理規(guī)則集,允許更新規(guī)則而不破壞現(xiàn)有會話和連接。而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ī)啟動

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
啟動防火墻
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)添加,測試

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-" 也會直接攔截,對數(shù)據(jù)庫等存儲也需要添加放行規(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

二、測試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ī)則編號

[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ī)則編號為1

2、刪除指定規(guī)則編號的規(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)刪除了,測試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)添加,測試

[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上測試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)文章

  • 我常用的一些linux命令小結(jié)

    我常用的一些linux命令小結(jié)

    linux命令熟練掌握后對效率提升有多大,這篇文章主要介紹了我常用的一些linux命令小結(jié),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-01-01
  • Linux下使用SSH遠(yuǎn)程執(zhí)行命令方法收集

    Linux下使用SSH遠(yuǎn)程執(zhí)行命令方法收集

    這篇文章主要介紹了Linux下使用SSH遠(yuǎn)程執(zhí)行命令方法收集,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-10-10
  • 配置apache支持apk ipk下載的方法

    配置apache支持apk ipk下載的方法

    這篇文章主要介紹了配置apache支持apk ipk下載的方法,需要的朋友可以參考下
    2014-04-04
  • Apache?HTTP?安裝和配置下載詳解

    Apache?HTTP?安裝和配置下載詳解

    這篇文章主要介紹了Apache?HTTP?安裝和配置下載,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2023-12-12
  • Linux下配置IP的三種實(shí)現(xiàn)方式

    Linux下配置IP的三種實(shí)現(xiàn)方式

    本文介紹了Linux系統(tǒng)中配置IP的三種方法:使用nmcli命令、ip命令以及通過ifcfg文件,nmcli命令是NetworkManager的命令行工具,配置后不會丟失;ip命令配置后重啟系統(tǒng)會丟失;ifcfg文件配置需手動激活
    2024-11-11
  • Linux中tcpdump命令實(shí)例詳解

    Linux中tcpdump命令實(shí)例詳解

    用簡單的話來定義tcpdump,就是:dump the traffic on a network,根據(jù)使用者的定義對網(wǎng)絡(luò)上的數(shù)據(jù)包進(jìn)行截獲的包分析工具。下面這篇文章主要給大家介紹了關(guān)于Linux中tcpdump命令的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-08-08
  • Apache服務(wù)器VirtualHost常用配置小結(jié)

    Apache服務(wù)器VirtualHost常用配置小結(jié)

    Apache服務(wù)器中的VirtualHost用來定義虛擬主機(jī),本文主要介紹了Apache服務(wù)器VirtualHost常用配置小結(jié),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-07-07
  • linux中的7z命令參數(shù)說明

    linux中的7z命令參數(shù)說明

    Linux中的7z命令具備多樣的參數(shù)來控制其功能,如添加文件、刪除、提取、更新存檔等。常用的命令包括a、d、e、x等,而開關(guān)如-o、-p、-m等則進(jìn)一步定義了操作的細(xì)節(jié),例如設(shè)置密碼、輸出目錄和壓縮方法。此命令強(qiáng)大且靈活,適合進(jìn)行文件壓縮和管理
    2024-09-09
  • linux中目錄與路徑常見相關(guān)命令

    linux中目錄與路徑常見相關(guān)命令

    在linux系統(tǒng)中操作文件,不像windows那么直觀,下面整理了一下Linux中的一些文件目錄與路徑的基本命令,需要的朋友參考下
    2017-04-04
  • centos環(huán)境下lnmp安裝配置

    centos環(huán)境下lnmp安裝配置

    這篇文章主要介紹了centos環(huán)境下lnmp安裝配置,大家參考使用吧
    2014-01-01

最新評論