Linux端口的开启Linux端口的开启一、firewall方式(centOS7。)二、修改iptables方式(centOS6。)一、firewall方式(centOS7。)查看防火墙状态firewallcmdstate 如果返回的是notrunning,那么需要先开启防火墙;开启防火墙systemctlstartfirewalld。service 再次查看防火墙状态,发现已开启!开启指定端口firewallcmdzonepublicaddport3306tcppermanent 显示success表示成功 zonepublic表示作用域为公共的 addport443tcp添加tcp协议的端口端口号为443 permanent永久生效,如果没有此参数,则只能维持当前服务生命周期内,重新启动后失效; 重启防火墙systemctlrestartfirewalld。service 系统没有任何提示表示成功!重新加载防火墙firewallcmdreload 显示success表示成功其他命令查看已开启的端口firewallcmdlistports关闭指定端口firewallcmdzonepublicremoveport8080tcppermanentsystemctlrestartfirewalld。servicefirewallcmdreload查看端口被哪一个进程占用netstatlnptgrep5672centos7默认没有netstat命令,需要安装nettools工具:安装nettoolsyuminstallynettools临时关闭防火墙systemctlstopfirewalld。service或者systemctlstopfirewalld永久关闭防火墙(必须先临时关闭防火墙,再执行该命令,进行永久关闭)systemctldisablefirewalld。service或者systemctldisablefirewalld二、修改iptables方式(centOS6。) centOS6。的linux版本是自带iptables的,所以可以直接使用该方式,centOS7不自带iptables的,所以要使用该方式,需要手动安装iptables后,再使用该方式!2。1修改iptables文件修改iptables〔rootlocalhostsbin〕vietcsysconfigiptables 2。2重启防火墙〔rootlocalhostsbin〕etcinit。diptablesrestart 三、注意事项 当在Linux中成功开启了某个端口,但是远程telnet还是无法ping通,是正常的! 因为3306端口没有被Linux进程监听,换句话说,就是该端口上没有运行任何程序!!! 如果这时,我将Mysql在Linux中启动,并配置完成,那么远程telnet该端口是可以成功的!!!