首页 > 系统相关 >linux-firewalld 和iptable的策略配置(nat 以及端口开放)

linux-firewalld 和iptable的策略配置(nat 以及端口开放)

时间:2023-12-22 21:35:36浏览次数:39  
标签:iptables cmd -- sudo 端口 firewalld iptable firewall nat

一、配置防火墙开发端口

1、
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld

2、配置防火墙规则
    firewall-cmd --permanent --add-service=ssh
    firewall-cmd --permanent --add-service=http
    firewall-cmd --permanent --add-service=https
    firewall-cmd --permanent --add-service=psp3
    firewall-cmd --permanent --add-service=smtp

3、重载防火墙规则
sudo firewall-cmd --reload

4、检查防火墙是否能正确应用
sudo firewall-cmd --reload

二、通过iptable开启端口

1、安装
sudo yum install iptables-services
2、启动
sudo systemctl start iptables
sudo systemctl enable iptables
3、配置规则
# 清除现有规则
sudo iptables -F
sudo iptables -X

# 设置默认策略
sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT

# 允许回环接口
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A OUTPUT -o lo -j ACCEPT

# 允许SSH (默认端口 22)
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# 允许HTTP (默认端口 80)
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT

# 允许HTTPS (默认端口 443)
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT

# 允许SMTP (默认端口 25)
sudo iptables -A INPUT -p tcp --dport 25 -j ACCEPT

# 允许POP3 (默认端口 110)
sudo iptables -A INPUT -p tcp --dport 110 -j ACCEPT

# 允许FTP (默认端口 21)
sudo iptables -A INPUT -p tcp --dport 21 -j ACCEPT

# 保存规则
sudo service iptables save

三、firewalld实现NAT方式共享上网的功能

1、开启firewalld
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld

2、配置规则
# 启用NAT
sudo firewall-cmd --permanent --zone=public --add-masquerade

# 允许转发
sudo firewall-cmd --permanent --add-forward-port=port=80:proto=tcp:toport=8080  # 举例,将80端口转发到本地8080端口

# 允许出站流量
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.0/24" masquerade'
该地址为内网地址

# 重新加载防火墙规则
sudo firewall-cmd --reload

3、开启ipv4转发
路径:打开 /etc/sysctl.conf 文件并确保以下行被取消注释:
net.ipv4.ip_forward = 1
后执行一下命令
sudo sysctl -p

4、配置网络接口
打开 /etc/sysconfig/network-scripts/ifcfg-eth0 文件(假设你的主要网络接口是 eth0)
并确保以下行被添加:
NM_CONTROLLED=no

5、重启网络服务
systemctl restart network.service


标签:iptables,cmd,--,sudo,端口,firewalld,iptable,firewall,nat
From: https://www.cnblogs.com/THuang/p/17922402.html

相关文章

  • 当 ChatGPT 有了身体会怎样?《Nature》预测 2024 科技大事丨 RTE 开发者日报 Vol.112
       开发者朋友们大家好: 这里是「RTE开发者日报」,每天和大家一起看新闻、聊八卦。我们的社区编辑团队会整理分享RTE(RealTimeEngagement)领域内「有话题的新闻」、「有态度的观点」、「有意思的数据」、「有思考的文章」、「有看点的会议」,但内容仅代表......
  • centos下Iptables的安装(离线)
    背景:要给公司服务器屏蔽端口,然后开服务IP白名单,修改完iptables文件后,想执行指令生效,发生指令不存在vim/etc/sysconfig/iptables-AINPUT-s10.xx.xx.xx/24-ptcp-mtcp--dport8888-jACCEPT-AINPUT-s10.xx.xx.xx/24-ptcp-mtcp--dport9999-jACCEPT然后重......
  • SAP-DB-服务器组-003-pacemaker集群-在AWS平台里-创建及配置-SAPHanaTopology资源及SA
    关于基础环境的安装,还是可以参考笔者另一篇文章,APP的部分《SAP-APP-服务器组-001-pacemaker集群的基础环境的安装部署》https://www.cnblogs.com/5201351/p/17899446.html 1、DB需要多安装  resource-agents-sap-hana[root@db01qq-5201351]#yuminstall-yresource-ag......
  • firewalld防火墙介绍
    systemctlstatusfirewalldsystemctlstartfirewalldsystemctlstopfirewalldsystemctlenablefirewalldsystemctldisablefirewalldsystemctlis-enabledfirewalldsystemctlis-activefirewalldsystemctlis-failedfirewalldsystemctlreloadfirewalldsyst......
  • CentOS7开启Firewalld防火墙日志记录获取被拦截的IP
    问题场景:在实际生产环境时使用该方法进行ES数据库白名单访问控制,但遇到业务侧反馈无法访问到ES数据库端口,需要加入到白名单,但业务侧用的IP业务侧无法准确给出于是通过如下面的方法解决这个问题1、firewalld的默认配置是不记录日志firewall-cmd--get-log-denied可以看到默认是off......
  • 深入 K8s 网络原理(二)- Service iptables 模式分析
    目录1.概述2.准备Service和Pods资源3.K8s里Service的实现原理3.1kube-proxy组件3.2iptables简介3.3iptables规则3.3.1Service,Pod和Host信息3.3.2从NodePort入手寻找iptables规则3.3.3从PREROUTING和OUTPUT链寻找K8s相关子链3.3.4总结下4.总结1......
  • 《Learning Transferable Visual Models From Natural Language Supervision》论文学
    一、Abstract最先进的计算机视觉系统被训练用以预测一组预定的固定目标类别。这种受限的监督方式限制了它们的通用性和可用性,因为需要额外的标记数据来指定任何新的视觉概念。因此,直接从关于图像的原始描述文本中学习是一个有希望的替代方法,它利用了更广泛的因特网监督来源。我......
  • Designated-Verifier Aggregate Signature Scheme With Sensitive Data Privacy Prote
    Abstract—AggregatesignaturesenablethesensornodesofIndustrialInternetofThingstosendtheirsignaturestotheaggregatortorealizesignaturecompression.Beforebeingstoredinthedatacenter,sensitivedataandnon-sensitivedatashouldadopt......
  • Istio从入门到精通—— 流量治理的原理 —— VirutalService —— RouteDestination
     流量治理的原理——VirutalService——RouteDestinationhttps://istio.io/latest/docs/reference/config/networking/virtual-service/#RouteDestinationL4routingruleweighteddestination.L4路由规则的加权目的地。FieldType......
  • Django报错UnorderedObjectListWarning: Pagination may yield inconsistent results
    Django报错UnorderedObjectListWarning:Paginationmayyieldinconsistentresults withanunorderedobject_list报错报错信息如下:Django报错Django报错UnorderedObjectListWarning:Paginationmayyieldinconsistentresults withanunorderedobject_list:<class......