網站首頁 編程語言 正文
Nginx禁止IP加端口訪問
使用iptables
限制對應端口,再利用Nginx將80端口轉發到對應端口
CentOS7默認的防火墻是 firewalle
,先看看服務器中有沒有安裝 iptables
[root@VM-0-3-centos ~]# service iptables status
Redirecting to /bin/systemctl status iptables.service
Unit iptables.service could not be found.
安裝 iptables
yum install -y iptables
關閉自帶的防火墻 firewalld
# 停止firewalld服務 systemctl stop firewalld # 禁用firewalld服務 systemctl mask firewalld
服務命令
# 啟動iptables systemctl start iptables.service # 停止iptables systemctl stop iptables.service # 重啟iptables systemctl restart iptables.service
禁止外部訪問8080
端口
iptables -I INPUT -p tcp --dport 8080 -j DROP
允許本機訪問8080
端口
iptables -I INPUT -s 127.0.0.1 -p tcp --dport 8080 -j ACCEPT
放行80
端口
iptables -A INPUT -p tcp --dport 80 -j ACCEPT iptables -A OUTPUT -p tcp --sport 80 -j ACCEPT
到此,就可以使用域名直接訪問8080
端口了,并且IP + 端口
的方式,也已經無法訪問
iptables
常用命令
# 查看iptables現有規則 iptables -L -n # 允許所有訪問 iptables -P INPUT ACCEPT # 清空所有默認規則 iptables -F # 清空所有自定義規則 iptables -X # 所有計數器歸0 iptables -Z # 允許來自于lo接口的數據包(本地訪問) iptables -A INPUT -i lo -j ACCEPT # 開放22端口 iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 開放21端口(FTP) iptables -A INPUT -p tcp --dport 21 -j ACCEPT # 開放80端口(HTTP) iptables -A INPUT -p tcp --dport 80 -j ACCEPT # 開放443端口(HTTPS) iptables -A INPUT -p tcp --dport 443 -j ACCEPT # 允許ping iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT # 允許接受本機請求之后的返回數據 RELATED,是為FTP設置的 iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT # 其他入站一律丟棄 iptables -P INPUT DROP # 所有出站一律綠燈 iptables -P OUTPUT ACCEPT # 所有轉發一律丟棄 iptables -P FORWARD DROP
原文鏈接:https://www.cnblogs.com/zilongmao/archive/2022/02/11/15883833.html
相關推薦
- 2022-10-19 R語言安裝以及手動安裝devtools的詳細圖文教程_R語言
- 2022-08-14 python中matplotlib調整圖例位置的方法實例_python
- 2022-06-22 android使用intent傳遞參數實現乘法計算_Android
- 2022-12-28 React組件通信實現流程詳解_React
- 2022-12-01 C++中高性能內存池的實現詳解_C 語言
- 2022-01-31 git統計當前項目代碼行數
- 2022-06-14 Qt拖放操作和打印操作的實現_C 語言
- 2022-05-21 基于C++實現酒店管理系統_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支