centos6.5 防火墙开放80端口
iptables -I INPUT -p tcp –dport 80 -j ACCEPT //注意,dport前面是两个-,其中-I是指在防火墙INPUT表最前面插入该条规则-p 用来指定协议的 –dport指定端口
那么我们再看看怎么关闭80端口
iptables -I INPUT -p tcp –dport 80 -j REJECT //很明显,就是把最后的ACCEPT改为REJECT
那么问题来了,重启后,该条规则会在重启后失效,所以我们需要保存对防火墙规则的修改
service iptables save (还没试过行不行)
Centos7 用firewalld代替iptables了,所以在Centos7下,也可以这么写命令

开放80端口
firewall-cmd –permanent –add-port=80/tcp #执行之后会提示success

firewall-cmd --reload #执行这条语句后才能生效

或者

firewalld-cmd --permanent --add-service=httpd

取消80端口对外开放

firewall-cmd –permanent –remove-port=80/tcp

firewalld-cmd --permanent --remove-service=httpd

再来个有趣点的,我们只将80端口对外开放一分钟

firewalld-cmd --permanent --add-service=httpd --timeout=1m

现在我们试着把1566端口的请求转移到80端口

firewall-cmd --add-forward-port=port=1566:proto=tcp:toport=80

让我们更近一步,把端口请求转发到另一个主机上

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=80:toaddr=10.0.3.92

如果没有意外的话,再次访问本地主机网页,发现并没有跳转到10.0.3.92去

这是因为我没哟没有开启防火墙的伪装功能,执行以下语句开启该功能就可以了

firewall-cmd --add-masquerade

这个功能怎么看开没开启呢(很明显,下面这个就没有)

firewall-cmd --zone=public --list-all

public (active)
target: default
icmp-block-inversion: no
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports:
protocols:
masquerade: no
forward-ports: port=1566:proto=tcp:toport=80:toaddr=
port=80:proto=tcp:toport=80:toaddr=10.0.3.92
sourceports:
icmp-blocks:
rich rules:

为什么上面加了一个--zone=public呢,这个值可以通过firewall-cmd --get-active-zone 查看

再来一个给力的,拒绝所有包有时候被DDoS攻击了之类的,就可以执行这条语句了。执行之后,ssh以及http等服务均无法从外部连接

firewall-cmd --panic-on

下面这条语句用于恢复正常

firewall-cmd --panic-off

看一下,防火墙目前允许那些服务通过

firewall-cmd --zone=public --list-services

看一下某个区域里面是否有某个接口

firewall-cmd --zone=public --query-interface=eth0

有没有注意到query这个词,于是我试了一下。还真的能查询

[root@localhost ~]# firewall-cmd --zone=public --query-service=ssh
yes
[root@localhost ~]#

有时候我们直接firewall-cmd --add-port=80/tcp,忘记加--permanent,但是实际上我们希望这条规则永久生效,应该如何呢

firewall-cmd --runtime-to-permanent

linux配置防火墙的更多相关文章

  1. Linux配置防火墙,开启80端口、3306端口

    Linux配置防火墙,开启80端口.3306端口   起因是因为想使用Navicat连接一下数据库,发现连接不上 通过查阅许多资料和多次测试发现是因为防火墙没有配置3306端口 话不多说,开整,同理, ...

  2. linux配置防火墙和重启防火墙

    1.在linux系统里面找到并打开编辑配置防火墙的文件,执行命令: vi /etc/sysconfig/iptables. 2.在上面打开的文件里面加入一下语句: -A INPUT -m state ...

  3. Linux配置防火墙8080端口

    1.查看防火墙状态,哪些端口开放了 /etc/init.d/iptables status 2.配置防火墙 vi /etc/sysconfig/iptables ################### ...

  4. Linux配置防火墙端口 8080端口

    1.查看防火墙状态,哪些端口开放了 /etc/init.d/iptables status 2.配置防火墙 vi /etc/sysconfig/iptables   ################# ...

  5. linux配置防火墙,开启端口

    Centos7,配置防火墙,开启端口 1.查看已开放的端口(默认不开放任何端口) firewall-cmd --list-ports 2.开启80端口 firewall-cmd --zone=publ ...

  6. linux配置防火墙详细步骤(iptables命令使用方法)

    通过本教程操作,请确认您能使用linux本机.如果您使用的是ssh远程,而又不能直接操作本机,那么建议您慎重,慎重,再慎重! 通过iptables我们可以为我们的Linux服务器配置有动态的防火墙,能 ...

  7. Linux配置防火墙 开启80端口的方法

    命令行输入: vi /etc/sysconfig/iptables 将 -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT ...

  8. Linux配置防火墙 开启80端口

    vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火 ...

  9. Linux配置防火墙,开启80端口、3306端口(转)

    vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(允许80端口通过防火 ...

  10. Linux配置防火墙,开启80port、3306port 可能会遇到的小问题

     vi /etc/sysconfig/iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT(同意80端口通 ...

随机推荐

  1. 玩linux就是不断的踩坑,踩坑。最近的坑。xpath firefox兼容问题,抓取表格。

    最近在抓取一个页面表格时发现,用firefox提取的xpath,不能用,仔细分析后,发现是提取的xpath多了一个tbody标签.在xpath路径中删掉这段就好了. last_A5='/html/bo ...

  2. C语言进度条实现。(转)

    #include <stdio.h> #include <windows.h> //跟新进度条函数 /* * 每传入一个参数就刷新一次进度条 * 当i*<=percent ...

  3. Mysql event事件用法

    公司的数据库需要进行定期删除数据,需要用到mysql event事件,学习和梳理这块知识. 1查看event是否开启 SHOW VARIABLES LIKE 'event_scheduler'; 2开 ...

  4. Problem C: 平面上的点——Point类 (III)

    Description 在数学上,平面直角坐标系上的点用X轴和Y轴上的两个坐标值唯一确定.现在我们封装一个“Point类”来实现平面上的点的操作. 根据“append.cc”,完成Point类的构造方 ...

  5. kettle在linux下执行任务

    1.下载 最新版下载 7.1 https://community.hitachivantara.com/docs/DOC-1009855 准备 上传任务文件 .kjb,.ktr 上传mysql 驱动 ...

  6. mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long'

    mybatis 异常 There is no getter for property named 'bizId' in 'class java.lang.Long' 当使用mybatis进行传参的时候 ...

  7. L251

    Beer before wine, or wine before beer; whatever the order, you’ll feel queer. That, at least, is the ...

  8. php usort

    <?phpfunction re($a,$b){ return ($a>$b)?1:-1; }$x=array(1,3,2,5,9);usort($x, 're');print_r($x) ...

  9. Golang AES加密

    package main import ( "crypto/aes" "crypto/cipher" "fmt" "os" ...

  10. Windows10下pip的配置文件设置

    pip.ini的内容: [global] index-url = http://mirrors.aliyun.com/pypi/simple trusted-host = mirrors.aliyun ...