<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Networking on D. Sébastien Taggart</title>
    <link>https://www.sebastientaggart.com/tags/networking/</link>
    <description>Recent content in Networking on D. Sébastien Taggart</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Sun, 04 Oct 2026 22:13:05 -0400</lastBuildDate>
    <atom:link href="https://www.sebastientaggart.com/tags/networking/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How to Forward SSH Port Using UFW/Iptables</title>
      <link>https://www.sebastientaggart.com/writing/iptables-forward-default-ssh/</link>
      <pubDate>Sat, 04 Jan 2020 21:11:38 -0500</pubDate>
      <guid>https://www.sebastientaggart.com/writing/iptables-forward-default-ssh/</guid>
      <description>How to forward the default SSH port from the public internet to an internal containerized service.</description>
      <content:encoded><![CDATA[<p>When managing self-hosted services like Git, you may find yourself needing to forward non-standard ports—say, <code>:10022</code>. This could lead to a Git address that looks like <code>ssh://git@git.sebastientaggart.com:10022/sebastientaggart/my-project.git</code>. While this setup can function smoothly, using a non-standard port comes with its own set of challenges: public networks might block those ports, you’ll need more extensive documentation, and let’s be honest—non-standard ports can detract from the overall aesthetic of your URLs.</p>
<p>In this guide, we’ll focus on how to utilize <code>ufw</code> (Uncomplicated Firewall) to forward traffic from a standard SSH port (<code>:22</code>) on one server to a non-standard port on another. Think of this as setting up a traffic cop for your network, ensuring that requests get to their intended destination without unnecessary fuss.</p>
<h3 id="setting-up-port-forwarding">Setting Up Port Forwarding</h3>
<p>Start by editing the <code>before.rules</code> file for <code>ufw</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo vi /etc/ufw/before.rules
</span></span></code></pre></div><p>Add the following lines to the file:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">*nat
</span></span><span class="line"><span class="cl">:PREROUTING ACCEPT <span class="o">[</span>0:0<span class="o">]</span>
</span></span><span class="line"><span class="cl">:POSTROUTING ACCEPT <span class="o">[</span>0:0<span class="o">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Forward traffic from this server (1.1.1.1:22) to a remote server (2.2.2.2:10022)</span>
</span></span><span class="line"><span class="cl">-A PREROUTING -i eth0 -d 1.1.1.1 -p tcp --dport <span class="m">22</span> -j DNAT --to-destination 2.2.2.2:10022
</span></span><span class="line"><span class="cl">-A POSTROUTING -o eth0 -j MASQUERADE
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">COMMIT
</span></span></code></pre></div><p>Replace <code>1.1.1.1</code> with the IP address of your server, and <code>2.2.2.2</code> with the IP of the target server.</p>
<p>After making these changes, reload <code>ufw</code> to apply the new rules:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo systemctl restart ufw
</span></span></code></pre></div><p>To ensure everything is functioning as intended, verify your settings with:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo iptables -t nat -L -n -v
</span></span></code></pre></div><p>Once you’ve completed these steps, your port <code>:22</code> will successfully forward to <code>:10022</code> on the remote server. Your Git addresses will now appear as follows: <code>ssh://git@git.sebastientaggart.com/sebastientaggart/my-project.git</code>.</p>
<h3 id="modifying-existing-rules">Modifying Existing Rules</h3>
<p>Now, what if you need to tweak existing rules? Flushing all iptables rules with <code>sudo iptables -F</code> is often too blunt an instrument; it can wreak havoc on your setup. Instead, it’s wiser to list your existing rules and delete them one by one as necessary.</p>
<p>To do this, list your current NAT rules with:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">iptables -t nat --line-numbers -L -n -v
</span></span></code></pre></div><p>The <code>--line-numbers</code> option is crucial, as it allows you to reference specific rules when you want to delete them. For example, if you want to remove the second rule in the <code>PREROUTING</code> chain, you’d issue:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">iptables -t nat -D PREROUTING <span class="m">2</span>
</span></span></code></pre></div><p>Remember, the instructions above assume you&rsquo;re adding rules to <code>/etc/ufw/before.rules</code> for the first time. If modifications are necessary, be sure to remove the old rules using the <code>-D</code> option before restarting <code>ufw</code> with <code>systemctl</code>.</p>
<h3 id="in-closing">In Closing</h3>
<p>By following these steps, you can seamlessly forward SSH ports using <code>ufw</code> and ensure that your self-hosted services run smoothly. Embracing a standard like port <code>:22</code> can simplify access and improve the security posture of your applications. After all, clarity in technology often leads to enhanced usability—and who doesn’t appreciate that?</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
