大网数据广告活动
服务器运维问答

Various firewall problems after VPS reboot [Firewall-cmd or iptables?]

· 52CE 我爱测

CentOS 7, VPS NGinx, virtualmin, pm2, mongodb, mongo-express, openvpn Hi guys, im new to VPS and linux in general but loving the flexibility and things im learning so please stay with me as im sure im about to look very ignorant.…

问题原文

原帖链接 · Cacoon · CC BY-SA 3.0

CentOS 7, VPS

NGinx, virtualmin, pm2, mongodb, mongo-express, openvpn

Hi guys, im new to VPS and linux in general but loving the flexibility and things im learning so please stay with me as im sure im about to look very ignorant.. :P

I have purchased a VPS, working well up until I rebooted it to fix some OpenVPN issues, on reboot I had to manually restart essentially everything and there seems to be some issues with my firewall now.

Some of my services seem to be working fine, for instance 'nginx' will properly reverse proxy to my running application, but mongodb wont grab database information, but it will work externally? (I can retrieve my database results with an outside product connecting with a URI...)

and I couldnt even connect with SSH! Anyway I modified some rule-sets on firewall-cmd and now I can finally connect to SSH but I am still having lots of trouble, lots of services seem to be not working due to firewall issues.

Id installed iptables following a tutorial but I have firewall-cmd which I am fine using is it safe to uninstall this? And is there a way to just open up all ports so I dont have to discover every problem of every service and open that port etc?

Will post any needed information from configs etc.

已采纳解答

原帖链接 · Alexander Tolkachev · CC BY-SA 3.0

Let's try to answer step-by-step:

  1. It's safe to uninstall firewalld? Yes, if you install iptables-services insted.
  2. Is there a way to just open up all ports? Yes but it's not safe to open all ports, some ports shouldn't be accessed from Internet, because they could use for some bad things, like DDoS third party servers.
  3. How to configure firewall? If you already installed iptables-services you could stop firewalld(systemctl stop firewalld), remove it, configure iptables and start it(systemctl start iptables) and don't forget to enable it(systemctl enable iptables). Simple configuration that allow access to several ports you could see below(there is open tcp ports 22,80, 443 and udp port 1194).

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-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 22 -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 443 -j ACCEPT

-A INPUT -p udp -m udp --dport 1194 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT

iptables configuration file in CentOS located in /etc/sysconfig/iptables

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。