<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>ufw 归档 - Tinyfool的个人网站</title>
	<atom:link href="https://codechina.org/tag/ufw/feed/" rel="self" type="application/rss+xml" />
	<link>https://codechina.org/tag/ufw/</link>
	<description></description>
	<lastBuildDate>Thu, 23 Jul 2020 02:56:28 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Github 企业版如何限制访问IP？</title>
		<link>https://codechina.org/2020/07/1722/</link>
					<comments>https://codechina.org/2020/07/1722/#respond</comments>
		
		<dc:creator><![CDATA[tinyfool]]></dc:creator>
		<pubDate>Thu, 23 Jul 2020 02:51:31 +0000</pubDate>
				<category><![CDATA[Github]]></category>
		<category><![CDATA[技术]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[ghe]]></category>
		<category><![CDATA[ufw]]></category>
		<guid isPermaLink="false">https://codechina.org/?p=1722</guid>

					<description><![CDATA[<p>有很多公司的 Github 企业版运行在完全的内网，有些公司的 Github 企业版运行在公网上。不管内网还是 [&#8230;]</p>
<p><a href="https://codechina.org/2020/07/1722/">Github 企业版如何限制访问IP？</a>最先出现在<a href="https://codechina.org">Tinyfool的个人网站</a>。</p>
]]></description>
										<content:encoded><![CDATA[
<p>有很多公司的 Github 企业版运行在完全的内网，有些公司的 Github 企业版运行在公网上。不管内网还是公网，从企业信息安全的角度上公司、安全人员或者管理人员总是希望给服务器加上 IP 访问控制。</p>



<p>我之前研究了下，原来 Github 企业版已经内置了 UFW 防火墙软件。其实，我们只需要简单的利用 UFW 防火墙增加一些访问规则就可以轻松的给服务器增加 IP 访问控制了。</p>



<span id="more-1722"></span>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow"><p><span style="color: inherit; font-size: inherit;">UFW 的全称是 Uncomplicated Firewall，其实就是“不复杂的防火墙”，从名字就知道，UFW 的设计就是为了简单易用的，我大概玩了玩，感觉比 iptables 确实简单亲民多了。从Ubuntu 8.04 LTS 以后，UFW 都是默认的防火墙选项了。</span></p></blockquote>



<p>首先，<code>ssh -p 122 admin@yourip</code> 连接到你的 Github 企业版终端后台。然后，执行：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">sudo ufw status</code></pre>



<p>输出结果大概为如下：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">Status: active

To                         Action      From
--                         ------      ----
ghe-1194                   ALLOW       Anywhere                  
ghe-122                    ALLOW       Anywhere                  
ghe-161                    ALLOW       Anywhere                  
ghe-22                     ALLOW       Anywhere                  
ghe-25                     ALLOW       Anywhere                  
ghe-443                    ALLOW       Anywhere                  
ghe-80                     ALLOW       Anywhere                  
ghe-8080                   ALLOW       Anywhere                  
ghe-8443                   ALLOW       Anywhere                  
ghe-9418                   ALLOW       Anywhere                  
ghe-1194 (v6)              ALLOW       Anywhere (v6)             
ghe-122 (v6)               ALLOW       Anywhere (v6)             
ghe-161 (v6)               ALLOW       Anywhere (v6)             
ghe-22 (v6)                ALLOW       Anywhere (v6)             
ghe-25 (v6)                ALLOW       Anywhere (v6)             
ghe-443 (v6)               ALLOW       Anywhere (v6)             
ghe-80 (v6)                ALLOW       Anywhere (v6)             
ghe-8080 (v6)              ALLOW       Anywhere (v6)             
ghe-8443 (v6)              ALLOW       Anywhere (v6)             
ghe-9418 (v6)              ALLOW       Anywhere (v6)             
</code></pre>



<p>这些就是当年 Github 企业版内置的标准规则，你大概对照 <a href="https://docs.github.com/cn/enterprise/2.21/admin/installation/network-ports">Github 企业版端口文档</a>，就大概知道这些端口是干啥的。</p>



<p>默认情况下不建议修改这些设置。但是如果你希望限制某些 IP 才能访问 Github 企业版的https端，那么你可以这样把某个 IP 例如 101.83.88.134 加入你的白名单IP：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">sudo ufw allow from 101.83.88.134 to any port 443</code></pre>



<p>系统会返回：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">Rule added</code></pre>



<p>这代表规则已经添加成功，你再执行 <code>sudo ufw status</code>，返回就会多一行：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">443                        ALLOW       101.80.99.250             
</code></pre>



<p>然后，当你把全部要加入白名单的 IP 都加入以后，你还需要把原有的默认任何 IP 都可以访问 443 的规则删除，也就是 <code>ghe-443 ALLOW Anywhere</code> 那一行。</p>



<p>怎么删除呢？首先你要得到规则号码，这时候你可以用 </p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">sudo ufw status numbered</code></pre>



<p>这样你就会发现，ghe-443 前面出现了一个编号，如下：</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">[ 6] ghe-443                    ALLOW IN    Anywhere                 </code></pre>



<p>然后你执行</p>



<pre class="wp-block-code"><code lang="bash" class="language-bash">sudo ufw delete 6</code></pre>



<p>这样默认任何 IP 可以访问 443 的规则就被删除了，这个时候你的服务器的 443 端口也就是 https 协议，只有你指定的 IP 可以访问了。</p>



<p>如果你想限制什么 IP 能访问服务器的终端后台，操作方法类似，只不过端口是 122。但是切记不要误操作，以免让自己无法登录终端后台进行维护了。</p>



<p>注：这个规则在 Github 企业版服务器升级的时候，会被抹除，所以，如果你指定好了相应的规则，你可以把它写成脚本，每次升级后再执行一次即可。</p>
<p><a href="https://codechina.org/2020/07/1722/">Github 企业版如何限制访问IP？</a>最先出现在<a href="https://codechina.org">Tinyfool的个人网站</a>。</p>
]]></content:encoded>
					
					<wfw:commentRss>https://codechina.org/2020/07/1722/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			<media:content url="https://codechina.org/wp-content/uploads/2020/06/1_zZ_-f5n45vnjrQt2G3FIyg-1024x340.png" medium="image" />
	</item>
	</channel>
</rss>
