时间:2021-07-01 10:21:17 帮助过:7人阅读
这样后,便可以真正关闭防火墙功能。远程连接mongodb成功!
上述连接:http://shaurong.blogspot.com/2014/07/centos-70-x64.html 内容如下(需翻 墙才可访问,所以就把原文复制过来了。望原作者莫见怪!):
点击查看文章内容
- [研究] CentOS <span style="color: #800080;">7.0</span> x64 的 iptables 與 firewall-<span style="color: #000000;">cmd 防火牆
- [研究] CentOS </span><span style="color: #800080;">7.0</span> x64 的 iptables 與 firewall-<span style="color: #000000;">cmd 防火牆
- </span><span style="color: #800080;">2014</span>-<span style="color: #800080;">07</span>-<span style="color: #800080;">25</span>
- <span style="color: #800080;">2014</span>-<span style="color: #800080;">08</span>-<span style="color: #800080;">01</span><span style="color: #000000;"> 修訂
- CentOS </span><span style="color: #800080;">7.0</span><span style="color: #000000;"> 開始,服務的管理使用變成用 systemctl,例如 httpd 的使用可用下面幾種方式
- # systemctl status</span>|start|stop|restart|<span style="color: #000000;">reload httpd
- OR
- # service httpd status</span>|start|stop|restart|<span style="color: #000000;">reload
- OR
- # apachectl configtest</span>|<span style="color: #000000;"> graceful
- service httpd 會自動重導指令到 systemctl 命令,問題不大。
- 但是防火牆就有問題了,因為架網站時本機測試正常,遠端關了防火牆卻仍連不上,所以做了點研究測試。
- [root@localhost </span>~]# yum -<span style="color: #000000;">y install httpd
- [root@localhost </span>~<span style="color: #000000;">]# service httpd restart
- Redirecting to </span>/bin/<span style="color: #000000;">systemctl restart httpd.service
- [root@localhost </span>~<span style="color: #000000;">]# service httpd status
- Redirecting to </span>/bin/<span style="color: #000000;">systemctl status httpd.service
- httpd.service </span>-<span style="color: #000000;"> The Apache HTTP Server
- Loaded: loaded (</span>/usr/lib/systemd/system/<span style="color: #000000;">httpd.service; disabled)
- Active: active (running) since Fri </span><span style="color: #800080;">2014</span>-<span style="color: #800080;">07</span>-<span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span><span style="color: #000000;"> CST; 21s ago
- Main PID: </span><span style="color: #800080;">14250</span><span style="color: #000000;"> (httpd)
- Status: </span><span style="color: #800000;">"</span><span style="color: #800000;">Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec</span><span style="color: #800000;">"</span><span style="color: #000000;">
- CGroup: </span>/system.slice/<span style="color: #000000;">httpd.service
- </span>? ? <span style="color: #800080;">14250</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- </span>? ? <span style="color: #800080;">14251</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- </span>? ? <span style="color: #800080;">14252</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- </span>? ? <span style="color: #800080;">14253</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- </span>? ? <span style="color: #800080;">14254</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- </span>? ? <span style="color: #800080;">14255</span> /usr/sbin/httpd -<span style="color: #000000;">DFOREGROUND
- Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Starting The Apache HTTP Se...
- Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain httpd[<span style="color: #800080;">14250</span><span style="color: #000000;">]: AH00558: httpd: Could not...
- Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span>:<span style="color: #800080;">58</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Started The Apache HTTP Ser...
- Hint: Some lines were ellipsized, use </span>-l to show <span style="color: #0000ff;">in</span><span style="color: #000000;"> full.
- [root@localhost </span>~]# ps aux |<span style="color: #000000;"> grep httpd
- root </span><span style="color: #800080;">14250</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.2</span> <span style="color: #800080;">209484</span> <span style="color: #800080;">4804</span> ? Ss <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- apache </span><span style="color: #800080;">14251</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- apache </span><span style="color: #800080;">14252</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- apache </span><span style="color: #800080;">14253</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- apache </span><span style="color: #800080;">14254</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- apache </span><span style="color: #800080;">14255</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.1</span> <span style="color: #800080;">211568</span> <span style="color: #800080;">2968</span> ? S <span style="color: #800080;">15</span>:<span style="color: #800080;">54</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> /usr/sbin/http -<span style="color: #000000;">DFOREGROUND
- root </span><span style="color: #800080;">14276</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">0.0</span> <span style="color: #800080;">112640</span> <span style="color: #800080;">980</span> pts/<span style="color: #800080;">1</span> R+ <span style="color: #800080;">15</span>:<span style="color: #800080;">55</span> <span style="color: #800080;">0</span>:<span style="color: #800080;">00</span> grep --color=<span style="color: #000000;">auto httpd
- [root@localhost </span>~<span style="color: #000000;">]#
- [root@localhost </span>~<span style="color: #000000;">]# service iptables stop
- Redirecting to </span>/bin/<span style="color: #000000;">systemctl stop iptables.service
- (下圖) 本機上測試正常
- (下圖) 遠端去連失敗
- 檢查防火牆狀態,是 inactive 的
- [root@localhost </span>~]# service iptables -<span style="color: #000000;">L
- The service command supports only basic LSB actions (start, stop, restart, </span><span style="color: #0000ff;">try</span>-restart, reload, force-reload, status). For other actions, please <span style="color: #0000ff;">try</span><span style="color: #000000;"> to use systemctl.
- [root@localhost </span>~<span style="color: #000000;">]# service iptables status
- Redirecting to </span>/bin/<span style="color: #000000;">systemctl status iptables.service
- iptables.service </span>-<span style="color: #000000;"> IPv4 firewall with iptables
- Loaded: loaded (</span>/usr/lib/systemd/system/<span style="color: #000000;">iptables.service; disabled)
- Active: inactive (dead)
- Jul </span><span style="color: #800080;">25</span> <span style="color: #800080;">15</span>:<span style="color: #800080;">56</span>:<span style="color: #800080;">53</span> localhost.localdomain systemd[<span style="color: #800080;">1</span><span style="color: #000000;">]: Stopped IPv4 firewall with ...
- Hint: Some lines were ellipsized, use </span>-l to show <span style="color: #0000ff;">in</span><span style="color: #000000;"> full.
- 列出防火牆 rules,居然仍有
- [root@localhost </span>~]# iptables -<span style="color: #000000;">L
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
- ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere ctstate RELATED,ESTABLISHED
- ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere
- INPUT_direct all </span>--<span style="color: #000000;"> anywhere anywhere
- INPUT_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
- INPUT_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
- ACCEPT icmp </span>--<span style="color: #000000;"> anywhere anywhere
- REJECT all </span>-- anywhere anywhere reject-with icmp-host-<span style="color: #000000;">prohibited
- Chain FORWARD (policy ACCEPT)
- target prot opt source destination
- ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere ctstate RELATED,ESTABLISHED
- ACCEPT all </span>--<span style="color: #000000;"> anywhere anywhere
- FORWARD_direct all </span>--<span style="color: #000000;"> anywhere anywhere
- FORWARD_IN_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
- FORWARD_IN_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
- FORWARD_OUT_ZONES_SOURCE all </span>--<span style="color: #000000;"> anywhere anywhere
- FORWARD_OUT_ZONES all </span>--<span style="color: #000000;"> anywhere anywhere
- ACCEPT icmp </span>--<span style="color: #000000;"> anywhere anywhere
- REJECT all </span>-- anywhere anywhere reject-with icmp-host-<span style="color: #000000;">prohibited
- Chain OUTPUT (policy ACCEPT)
- target prot opt source destination
- OUTPUT_direct all </span>--<span style="color: #000000;"> anywhere anywhere
- Chain FORWARD_IN_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- FWDI_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- FWDI_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- Chain FORWARD_IN_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FORWARD_OUT_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- FWDO_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- FWDO_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- Chain FORWARD_OUT_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FORWARD_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDI_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
- target prot opt source destination
- FWDI_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
- FWDI_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
- FWDI_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
- Chain FWDI_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDI_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDI_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDO_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
- target prot opt source destination
- FWDO_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
- FWDO_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
- FWDO_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
- Chain FWDO_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDO_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain FWDO_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain INPUT_ZONES (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- IN_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- IN_public all </span>-- anywhere anywhere [<span style="color: #0000ff;">goto</span><span style="color: #000000;">]
- Chain INPUT_ZONES_SOURCE (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain INPUT_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain IN_public (</span><span style="color: #800080;">2</span><span style="color: #000000;"> references)
- target prot opt source destination
- IN_public_log all </span>--<span style="color: #000000;"> anywhere anywhere
- IN_public_deny all </span>--<span style="color: #000000;"> anywhere anywhere
- IN_public_allow all </span>--<span style="color: #000000;"> anywhere anywhere
- Chain IN_public_allow (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- ACCEPT tcp </span>--<span style="color: #000000;"> anywhere anywhere tcp dpt:ssh ctstate NEW
- Chain IN_public_deny (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain IN_public_log (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- Chain OUTPUT_direct (</span><span style="color: #800080;">1</span><span style="color: #000000;"> references)
- target prot opt source destination
- [root@localhost </span>~<span style="color: #000000;">]#
- 經過研究發現,應該要改用 firewall</span>-<span style="color: #000000;">cmd 命令
- 要暫時開放 http port,可執行
- # firewall</span>-cmd --add-service=<span style="color: #000000;">http
- 要永久開放 http port,可執行
- # firewall</span>-cmd --permanent --add-service=<span style="color: #000000;">http
- # systemctl restart firewalld
- 要停掉
- [root@localhost </span>~<span style="color: #000000;">]# systemctl stop firewalld
- 下面確認一下,真的停掉了
- [root@localhost </span>~]# iptables -<span style="color: #000000;">L
- Chain INPUT (policy ACCEPT)
- target prot opt source destination
- Chain FORWARD (policy ACCEPT)
- target prot opt source destination
- Chain OUTPUT (policy ACCEPT)
- target prot opt source destination
- [root@localhost </span>~<span style="color: #000000;">]#
- (下圖) 再從遠端連上網站看看,成功了
- 也就是 service iptables stop 無法停掉防火牆了 ( 看下面訊息該有支援,Bug 嗎 </span>?<span style="color: #000000;">)
- [root@localhost </span>~<span style="color: #000000;">]# service iptables
- The service command supports only basic LSB actions (start, stop, restart, </span><span style="color: #0000ff;">try</span>-restart, reload, force-reload, status). For other actions, please <span style="color: #0000ff;">try</span><span style="color: #000000;"> to use systemctl.
- 設定 httpd 隨作業系統啟動
- systemctl enable httpd
- 其他常用 firewall</span>-<span style="color: #000000;">cmd 命令
- # firewall</span>-cmd --<span style="color: #000000;">state
- # firewall</span>-cmd --list-<span style="color: #000000;">all
- # firewall</span>-cmd --list-<span style="color: #000000;">interfaces
- # firewall</span>-cmd --<span style="color: #0000ff;">get</span>-<span style="color: #000000;">service
- # firewall</span>-cmd --query-<span style="color: #000000;">service service_name
- # firewall</span>-cmd --add-port=<span style="color: #800080;">8080</span>/<span style="color: #000000;">tcp
- (完)
- 相關
- [研究] CentOS </span><span style="color: #800080;">7.0</span><span style="color: #000000;"> x64 的網站架設與防火牆
- http:</span><span style="color: #008000;">//</span><span style="color: #008000;">shaurong.blogspot.tw/2014/07/centos-linux-701406.html</span>
- <span style="color: #000000;">
- Installing LAMP (Linux, Apache, MariaDB, PHP</span>/PhpMyAdmin) <span style="color: #0000ff;">in</span> RHEL/CentOS <span style="color: #800080;">7.0</span><span style="color: #000000;">
- http:</span><span style="color: #008000;">//</span><span style="color: #008000;">www.tecmint.com/install-lamp-in-centos-7/</span>
三、RED7中通过yum安装mongodb的官方步骤:
http://docs.mongodb.org/master/tutorial/install-mongodb-on-red-hat/?_ga=1.11182708.1945386581.1439519252
四、关于RED 7中关闭防火墙命令的描述如下:
http://linux.it.net.cn/CentOS/fast/2014/1102/7635.html
远程连接mongodb时,27017端口连接不上的解决办法
标签: