1.查看防火墙对外开放了哪些端口

[root@hadoop110 ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ tcp dpt:
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 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/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
target prot opt source destination

2.centos6.0防火墙操作:

配置文件:/etc/sysconfig/iptables

开启某个端口号有两种方式:一种是命令方式,一种是修改配置文件方式

查看防火墙状态:chkconfig iptables --list

[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭

开启防火墙(重启后永久生效):chkconfig iptables on
关闭防火墙(重启后永久生效):chkconfig iptables off

[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭
[root@hadoop110 ~]# chkconfig iptables off
[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :关闭 :关闭 :关闭 :关闭 :关闭
[root@hadoop110 ~]# chkconfig iptables on
[root@hadoop110 ~]# chkconfig iptables --list
iptables :关闭 :关闭 :启用 :启用 :启用 :启用 :关闭
[root@hadoop110 ~]#

开启防火墙(即时生效,重启后失效):service iptables start
关闭防火墙(即时生效,重启后失效):service iptables stop
重启防火墙:service iptables restart

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
\表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ tcp dpt:
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain FORWARD (policy ACCEPT)
num target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

3.开启某个端口号(如80端口号,命令方式)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

[root@hadoop110 ~]# iptables -A INPUT -p tcp -m state --state  NEW  -m tcp --dport  -j ACCEPT

保存开启的端口号
service iptables save

[root@hadoop110 ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]
[root@hadoop110 ~]# iptables status
Bad argument `status'
Try `iptables -h' or 'iptables --help' for more information.

重新启动防火墙
service iptables restart

[root@hadoop110 ~]# service iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ tcp dpt:
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt: Chain FORWARD (policy ACCEPT)
num target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

开启某个范围的端口号(如18881~65534,命令方式)
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 18881:65534 -j ACCEPT

[root@hadoop110 ~]# iptables -A INPUT -p tcp -m state --state  NEW  -m tcp --dport : -j ACCEPT

保存开启的端口号
service iptables save

[root@hadoop110 ~]# service iptables save
iptables:将防火墙规则保存到 /etc/sysconfig/iptables: [确定]

重新启动防火墙
service iptables restart

查看开启的端口号
service iptables status

[root@hadoop110 ~]# service iptables status
表格:filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ tcp dpt:
ACCEPT all -- 0.0.0.0/ 0.0.0.0/ state RELATED,ESTABLISHED
ACCEPT icmp -- 0.0.0.0/ 0.0.0.0/
ACCEPT all -- 0.0.0.0/ 0.0.0.0/
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpt:
ACCEPT tcp -- 0.0.0.0/ 0.0.0.0/ state NEW tcp dpts:: Chain FORWARD (policy ACCEPT)
num target prot opt source destination
REJECT all -- 0.0.0.0/ 0.0.0.0/ reject-with icmp-host-prohibited Chain OUTPUT (policy ACCEPT)
num target prot opt source destination

4.通过修改配置文件开启端口号(如80端口号)
 vi /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
启动防火墙
service iptables restart

参数说明:
–A 参数就看成是添加一条规则
–p 指定是什么协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
–dport 就是目标端口,当数据从外部进入服务器为目标端口

–j 就是指定是 ACCEPT -接收 或者 DROP 不接收

原文:https://blog.csdn.net/u014079773/article/details/79745819

centos6+如何对外开放80,3306端口号或者其他端口号的更多相关文章

  1. linux mysql 查看默认端口号和修改端口号

    如何查看mysql 默认端口号和修改端口号 2015-03-19 17:42:18 1. 登录mysql [root@test /]# mysql -u root -p Enter password: ...

  2. 如何查看mysql 默认端口号和修改端口号

    http://blog.itpub.net/26148431/viewspace-1466379/ 1,登录mysql 2,使用命令show global variables like 'port'; ...

  3. 查看mysql 默认端口号和修改端口号

    1. 登录mysql mysql -u root -p //输入密码 2. 使用命令show global variables like 'port';查看端口号 mysql> show glo ...

  4. CentOS7查看开放端口命令及开放端口号

    CentOS 7查看以开放端口命令:firewall-cmd —list-ports 查看端口是否开放命令:第一个方法就是使用lsof -i:端口号命令行,例如lsof -i:80.如果没有任何信息输 ...

  5. 登录MySQL非默认3306端口号的语句

    这里登陆的是mysql3308端口号的数据库 mysql -P3308 -p用户名 -u密码

  6. Centos7 开放80,3306端口解决办法

    所有扯iptables的文章都是扯淡!!! centos 7 默认防火墙由firewalld来管理!关iptables屁事! 以开放80端口为例,执行以下命令: 开放80端口:firewall-cmd ...

  7. SQL Server 端口号的使用

    SQL Server 端口号的使用 服务器地址  逗号 端口号 服务器地址,端口号 xxx.xxx.xxx.xxx,0000 www.xxx.com,1533  (1533是SQL Server 的端 ...

  8. linux-sftp-指定端口号登录远程主机

    sftp -oPort=60001 root@192.168.0.254 -o选项来指定端口号 -oPort=远程端口号

  9. 调试技巧--Windows端口号是否被占用

    调试技巧--Windows端口号是否被占用 一.端口概念 10.0.0.0~10.255.255.255,172.16.0.0~172.16.255.255, 192.168.0.0~192.168. ...

随机推荐

  1. Usage of API documented as @since 1.8+”报错的解决办法

    参考资料 1.https://blog.csdn.net/a499477783/article/details/78967586/

  2. 如何用navicat premium 链接Oracel数据库

    1.连接->Oracle 2.填写配置信息 3.填写完成后连接测试,发现报错 : TNS:listener does not currently know of service requeste ...

  3. solrcloud上传collection配置

    建议:上传多个collection的配置文件,建议修改配置文件名字,在solr.xml中按照文件名来引用collection对应的schema和solrconfig.xml文件,这样无论你多个coll ...

  4. 使用laravel实现用户的登陆

    首先在 php artisan 里面 make:auth 生产一个门脸类 修改配置文件里面要哪个模型登陆 模型得继承一下才能 先写一下注册 密码必须要使用laravel的加密方法,使用MD5都没用 l ...

  5. 关于PHP的一个坑爹问题(页面刷新)

    最近在用PHP做一个服务端和一个客户端,在快要完工的时候,出现了一个重大问题---- 当在客户端手动输入IP和端口的时候,一按连接,OK,连接成功,嘻嘻,就在我自以为大功告成的时候,来了个晴天霹雳,一 ...

  6. instanceof php

    instdnceof php5  的一个新成员 功能: 使用这个关键字可以确定一个对象是否是类的实例,是否是累的子类 ,还是实现了某个特定的接口. <?php class A{} class B ...

  7. 697. Degree of an Array 频率最高元素的最小覆盖子数组

    [抄题]: Given a non-empty array of non-negative integers nums, the degree of this array is defined as ...

  8. postfix配置积累(不断的积累)

    postfix 配置 1.mail_name 默认是Postfix.在收件人信头可以查看,如果不想让别人知道你是用postfix发的,则可以改成其它名字,如:postconf -e mail_name ...

  9. 黑盒测试实践-任务进度-Day03

    任务进度11-28 使用工具 selenium 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 经过了前两天的学习任务的安排,以下是大家的任务进度: 华同学(任务1) 1.今天就接 ...

  10. DataAnnotationsModelValidator-基于数据注解方式的model验证器

    http://www.cnblogs.com/artech/archive/2012/04/10/how-mvc-works.html http://www.cnblogs.com/artech/ar ...