配置防火牆,開啟80埠、3306埠 & iptables 使用詳解
1:配置防火牆,開啟80埠、3306埠
vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允許80埠通過防火牆)-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允許3306埠通過防火牆)
特別提示:很多網友把這兩條規則新增到防火牆配置的最後一行,導致防火牆啟動失敗,正確的應該是新增到預設的22埠這條規則的下面
新增好之後防火牆規則如下所示:
######################################
# 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 -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
#####################################
/etc/init.d/iptables restart #最後重啟防火牆使配置生效
2:iptables 使用詳解
Centos 6 iptables 配置
Ben
2011/12/24
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
3 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
7 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
-----------
插入1條記錄
[[email protected] ben.liu]# iptables -I INPUT -j ACCEPT -s 172.16.0.0/16 -p tcp --dport 443 -m state --state NEW
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 tcp dpt:443 state NEW
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
7 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
-
[[email protected] ben.liu]# iptables-save
# Generated by iptables-save v1.4.7 on Sat Dec 24 16:50:09 2011
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [201:20052]
-A INPUT -s 172.16.0.0/16 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2256 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sat Dec 24 16:50:09 2011
--
修改1條記錄:比如第7條 state NEW tcp dpt:22
[[email protected] ben.liu]# iptables -R INPUT 7 -s 172.16.0.0/16 -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
[[email protected] ben.liu]# iptables status
Bad argument `status'
Try `iptables -h' or 'iptables --help' for more information.
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 tcp dpt:443 state NEW
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
7 ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 state NEW tcp dpt:22
8 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
--
刪除1條記錄,比如:第7條
[[email protected] ben.liu]# iptables -D INPUT 7
[[email protected] ben.liu]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.16.0.0/16 anywhere tcp dpt:https state NEW
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:pcc-mfp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[[email protected] ben.liu]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 tcp dpt:443 state NEW
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 tcp dpt:443 state NEW
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
7 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
---
清空所有INPUT 記錄
[[email protected] ben.liu]# iptables-save > /etc/sysconfig/iptables.bak
[[email protected] ben.liu]# iptables -F INPUT
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[[email protected] ben.liu]# iptables-save > /etc/sysconfig/iptables.bak
[[email protected] ben.liu]# iptables -F INPUT
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
恢復以前儲存的記錄:
[[email protected] ben.liu]# iptables-restore /etc/sysconfig/iptables.bak
[[email protected] ben.liu]# service iptables status
Table: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT tcp -- 172.16.0.0/16 0.0.0.0/0 tcp dpt:443 state NEW
2 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:2256
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
4 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
5 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
6 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:80
7 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
1 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[[email protected] ben.liu]# iptables-save
# Generated by iptables-save v1.4.7 on Sat Dec 24 17:24:57 2011
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [44:5152]
-A INPUT -s 172.16.0.0/16 -p tcp -m tcp --dport 443 -m state --state NEW -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 2256 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Sat Dec 24 17:24:57 2011
----------
檢視iptables 啟動的規則檔案:
[[email protected] ben.liu]# 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 80 -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服務
[[email protected] ben.liu]# service iptables stop
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
[[email protected] ben.liu]# chkconfig --level 35 iptables off
[[email protected] ben.liu]# chkconfig --level 35 iptables on
[[email protected] ben.liu]# service iptables start
iptables: Applying firewall rules: [ OK ]
[[email protected] ben.liu]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]相關推薦
配置防火牆,開啟80埠、3306埠 & iptables 使用詳解
1:配置防火牆,開啟80埠、3306埠 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允許80埠通過防火牆) -A INPUT -m state –state NEW -m
Linux配置防火牆,開啟80埠、3306埠 可能會遇到的小問題
vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允許80埠通過防火牆) -A INPUT -m state –state NEW
Centos7,配置防火牆,開啟埠
1.centos7版本對防火牆進行 加強,不再使用原來的iptables,啟用firewall 1.檢視已開放的埠(預設不開放任何埠) firewall-cmd --list-ports
阿里雲 伺服器 centos 開啟80埠、3306埠
1:配置防火牆,開啟80埠、3306埠 vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允許80埠通過防火牆) -A INPUT -
Unix環境程式設計之二:檔案描述符、開啟檔案表、v節點關係詳解
一、檔案描述符概念 Linux 系統中,把一切都看做是檔案,當程序開啟現有檔案或建立新檔案時,核心向程序返回一個檔案描述符,檔案描述符就是核心為了高效管理已被開啟的檔案所建立的索引,用來指向被開啟的檔案,所有執行I/O操作的系統呼叫都會通過檔案描述符。 二、檔案
Linux配置防火墻,開啟80端口、3306端口
ima ice -a 技術分享 image dport 導致 restart -s 起因是因為想使用Navicat連接一下數據庫,發現連接不上 通過查閱許多資料和多次測試發現是因為防火墻沒有配置3306端口 話不多說,開整,同理,80端口同樣配置,首先進入防火墻配置文件 s
linux開啟防火牆,開放80埠,開放mysql的3306埠,開放svn的3609埠,開放tomcat的8080埠。
vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允許80埠通過防火牆) -A INPUT -m state –state NEW -m
linux centos開啟 80、22、3306埠方案
1、設定 [[email protected] ~]# /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT [[email protected] ~]# /sbin/iptables -I INP
ubuntu下設定防火牆,開啟指定埠
ubuntu下開放埠主要有兩種辦法: 自帶的防火牆 使用iptables 安裝iptables: $ sudo apt-get install iptables 1 新增規則: $ sudo iptables -I INPUT -p tcp --dport 80 -
Centos7防火牆用法,centos7開放埠、關閉埠
Centos7不再使用iptables而是使用firewall 所以防火牆相關的命令也改了 檢視開放的埠 firewall-cmd --list-ports 開放80埠 firewall-cmd --zone=public --add-port=80/tcp --p
CentOS 6.8 配置防火牆,開放8080埠
環境:宿主機MAC,虛擬機器CentOS 6.8 問題:相互之間可以ping通,但是宿主機訪問不了虛擬機器8080埠 解決辦法: 開啟配置檔案 sudo vim /etc/sysconfig/iptables 按下a,進入編輯 加入這一行 -A INPUT -
CentOS學習21_ CentOS 配置防火牆操作例項(啟、停、開、閉埠)
CentOS 配置防火牆操作例項(啟、停、開、閉埠): 注:防火牆的基本操作命令: 查詢防火牆狀態: [[email protected] ~]# service iptables status<回車> 停止防火牆: [[email
CentOS 配置防火牆操作例項(啟、停、開、閉埠)整理
CentOS 配置防火牆操作例項(啟、停、開、閉埠): 注:防火牆的基本操作命令:查詢防火牆狀態:[[email protected] ~]# service iptables status 停止防火牆:[[email protected] ~]# s
phpstudy執行時80埠和3306埠被佔用解決方法
80埠負責Apache執行 3306埠負責MySQL執行 當這兩個埠被佔用時,則不能執行程式 首先檢視什麼程式佔用埠,按住window+R,輸入cmd,點確定 進入cmd的介面,在輸入“netstat -ano” 再按回車鍵 找到埠以及對應的PID值 然後
linux下根據根據程序號查埠、根據埠號查程序號彙總,以及netstat的相關資料(工作中匱乏的知識)
根據埠查程序: lsof -i:port netstat -nap | grep port 根據程序號查埠: lsof -i|grep pid netstat -nap | grep pid 根據程序名
phpstudy配置https,開啟httpd-ssl.conf,Apache就啟動不了的原因
前幾天公司的網站需要升級https,網上有很多教程詳細描述了怎麼在phpstudy上面配置https,自己也是按照這些教程一步一步來的,但是複製檔案到httpd-ssl.conf,Apache就啟動不了,出現這個的原因肯定是複製的內容有錯誤,有錯誤的地方很大一部分就是在引用證書那一部分,一定要注意檢
除了花生殼,還有每步、nat123埠對映等不少可以選擇的
有一段時間用了花生殼,6.5的版本還是可以的,但後來強制升級新花生後,功能限制好多,感覺就像是剪下版。受不了了,就找其他用。 除了花生殼,還有每步、nat123埠對映、金萬維等可以用用。 花生殼:需要轉入域名使用。限制比較多。 每步動態域名:需要轉入域名使用。以前是最多人
業余草分享面試題,JVM結構、GC工作機制詳解
影響 根節點 tac 關註 共享 產生 我想 tar 效果 題外話:最近在應聘阿裏2015暑期實習,感觸頗多。機會總是留給有準備的人的,所以平常一定要註意知識的鞏固和積累。知識的深度也要有一定的理解,不比別人知道的多,公司幹嘛選你?關於JVM和GC,我相信學java的絕大部
[轉帖]記憶體核心頻率、工作頻率,等效頻率、預讀取技術詳解
https://blog.csdn.net/hit_shaoqi/article/details/78121556 ■何為記憶體頻率 對於記憶體條,相信大家並不陌生。因為記憶體已經成為每臺電腦的必備配件,從EDO、SDRAM、DDR、DDR2再到現如今的DDR3記憶體,變化可謂是翻天覆地。記憶體無論是在
如何安裝Nexus Repository Manager OSS 3.x,如何搭建管理Maven私服,win10、win7通用安裝詳解,附:錯誤解決方案。
今天搭建一個Maven私服花了不少功夫,查閱了很多安裝的帖子以及百度了很多錯誤解決方案,然後將所有的帖子精華部分,附上我的經驗來帶給大家一個特別詳細的安裝方案,所以該文章大部分可以說是總結別人帖子。話不多說,開始安裝: 1.下載 &nb