<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生信菜鸟团 &#187; 防火墙</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/%e9%98%b2%e7%81%ab%e5%a2%99/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>linux服务器管理&#8211;防火墙设置命令iptables</title>
		<link>http://www.bio-info-trainee.com/1688.html</link>
		<comments>http://www.bio-info-trainee.com/1688.html#comments</comments>
		<pubDate>Sat, 04 Jun 2016 01:32:07 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[生信基础]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[端口]]></category>
		<category><![CDATA[防火墙]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=1688</guid>
		<description><![CDATA[如果我们想新开一个端口给别人访问，我们就需要设置防火墙，比如我想开3838端口给 &#8230; <a href="http://www.bio-info-trainee.com/1688.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div>
<div>如果我们想新开一个端口给别人访问，我们就需要设置防火墙，<strong>比如我想开3838端口给shiny程序使用</strong>，下面我重点讲解这个实例，其余开放端口，关闭端口大家继续学习就好。</div>
<div>如果你使用的是ssh远程，而又不能直接操作本机，<span style="color: #ff00ff;"><strong>那么建议你慎重，慎重，再慎重！（一旦你把22端口给搞死了，你就无法登陆你的服务器了！！！）</strong></span></div>
<div><span id="more-1688"></span></div>
<div>通过iptables我们可以为我们的Linux服务器配置有动态的防火墙，能够指定并记住为发送或接收信息包所建立的连接的状态，是一套用来设置、维护和检查Linux内核的IP包过滤规则的命令包。</div>
<div>首先配置好防火墙 <b>sudo vim<span style="color: #ff0000;"> /etc/sysconfig/iptables </span></b>让该端口可以被访问</div>
<div><a href="http://www.bio-info-trainee.com/wp-content/uploads/2016/06/3.png"><img class="alignnone size-full wp-image-1680" src="http://www.bio-info-trainee.com/wp-content/uploads/2016/06/3.png" alt="3" width="593" height="264" /></a></div>
<div>然后进去修改即可，上面红圈出来的那句话就是我添加的，意思是开放3838端口给用户使用。</div>
<div>修改之后并不是防火墙规则马上生效，还需要一个步骤，我搜索了一些资料，里面是这样讲的，我发现它的教程太旧了</div>
<blockquote>
<div>这里很多人会想到/etc/rc.d/init.d/iptables save指令</div>
<div>但是一旦你这么干了你刚才的修改内容就白做了。。。</div>
<div>只修改/etc/sysconfig/iptables 使其生效的办法是修改好后先service iptables restart</div>
<div>然后才调用/etc/rc.d/init.d/iptables save</div>
<div>因为/etc/rc.d/init.d/iptables save会在iptables服务启动时重新加载，要是在重启之前直接先调用了/etc/rc.d/init.d/iptables save那么你的/etc/sysconfig/iptables 配置就回滚到上次启动服务的配置了，这点必须注意！！！</div>
</blockquote>
<p>因为我是新的系统（RedHat 7, Ubuntu 15.04+, SLES 12+) ，结合我对该教程的理解。所以我用的是</p>
</div>
<p>&nbsp;</p>
<div>sudo systemctl restart iptables  命令，果然，马上3838端口就可以被访问了，我的shiny程序也可以完整的使用啦。</div>
<div>再简单解释一下刚才修改的<strong>防火墙配置文件</strong><b><span style="color: #ff0000;"> /etc/sysconfig/iptables</span></b> 的那句话的意义：</div>
<blockquote>
<div>
<ol>
<li>-A：指定链名</li>
<li>-p：指定协议类型</li>
<li>-d：指定目标地址</li>
<li>--dport：指定目标端口（destination port 目的端口）</li>
<li>--sport：指定源端口（source port 源端口）</li>
<li>-j：指定动作类型</li>
</ol>
</div>
</blockquote>
<div>我还查了好多其它资料，开始好像暂时用不着，就先不学习了，但是那些资料大多太陈旧了，请睁大你的慧眼，消化了它人的指导，再来自己运行。</div>
<div></div>
<div></div>
<div></div>
<div>
<div>也可以不去打开那个文件进行修改，而且命令行形式一条条记录的添加</div>
<div>
<blockquote>
<div>
<ol>
<li>例如我给SSH加放行的语句：</li>
<li>添加input记录： iptables -A INPUT -p tcp --dport <span style="color: #c00000;">22</span> -j ACCEPT</li>
<li>添加output记录： iptables -A OUTPUT -p tcp --sport <span style="color: #c00000;">22</span> -j ACCEPT</li>
<li>最后注意需要再执行一下 /etc/init.d/iptables save，这样这两条语句就保存到刚才那个/etc/sysconfig/iptables 文件中了。</li>
</ol>
</div>
</blockquote>
</div>
<div></div>
<div></div>
<div>删除端口就非常简单了：</div>
<div>可能有时候需要删除规则，最简单就是修改一下/etc/sysconfig/iptables然后service iptables restart,最后/etc/rc.d/init.d/iptables save即可。</div>
<div></div>
<div>还可以彻底禁止某IP访问:</div>
<div>
<ol>
<li>#屏蔽单个IP的命令是</li>
<li>iptables -I INPUT -s 123.45.6.7 -j DROP</li>
<li>#封整个段即从123.0.0.1到123.255.255.254的命令</li>
<li>iptables -I INPUT -s 123.0.0.0/8 -j DROP</li>
<li>#封IP段即从123.45.0.1到123.45.255.254的命令</li>
<li>iptables -I INPUT -s 124.45.0.0/16 -j DROP</li>
<li>#封IP段即从123.45.6.1到123.45.6.254的命令是</li>
<li>iptables -I INPUT -s 123.45.6.0/24 -j DROP</li>
<li>指令I是insert指令 但是该指令会insert在正确位置并不像A指令看你自己的排序位置，因此用屏蔽因为必须在一开始就要加 载屏蔽IP，所以必须使用I命令加载，然后注意执行/etc/rc.d/init.d/iptables save进行保存后重启服务即可</li>
</ol>
</div>
<div></div>
<div>在linux关闭防火墙可以这样：<br />
1. 重启系统生效<br />
开启： chkconfig iptables on<br />
关闭： chkconfig iptables off2. 即时生效，重启后失效<br />
开启： service iptables start<br />
关闭： service iptables stop</div>
</div>
<div></div>
<div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/1688.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
