Most local networks are ideally protected from the outside world. If you've ever tried installing a service, such as a web server or a

Nextcloud

instance, at home, then you probably know from first hand experience that while the service is easy to reach from inside the network, it's unreachable over the worldwide web. There are both technical and security reasons for this, but sometimes you want to open up access to something within a local network to the outside world. This article discusses what you need to do to route traffic from the Internet into your local network correctly and safely.

Local and public IP addresses {#_local_and_public_ip_addresses}

The first thing you need to understand is the difference between a local IP address and a public IP address. Currently, most of the world (still) uses an addressing system called IPv4, which famously has a limited pool of numbers available to assign to networked electronic devices. In fact, there are more networked devices in the world than there are IPv4 addresses, and yet IPv4 continues to function. This is made possible by local addresses.

All local networks in the world use the *same* address pools. For instance, my home router's local IP address is 192.168.1.1. One of those is the same number, probably, as your home router, and yet when I navigate to 192.168.1.1, I reach *my* router's login screen and not *your* router's login screen. That's because your home router actually has two addresses: one public and one local, and the public one shields the local one from being detected by the Internet, much less from being confused for someone else's 192.168.1.1.

Network of networks [IMG]

This, in fact, is why the Internet is called the Internet: it's a "web" of interconnected, and otherwise self-contained, networks. Each network, whether it's your workplace or your home or your school or a big data center or the "cloud" itself, is a collection of connected hosts that in turn communicate with a gateway (usually a router) that manages traffic from the Internet and into the local network, and out of the local network to the Internet.

What this means is that if you're trying to access a computer on a network that's not the network you're currently attached to, then knowing the local address of that computer does you no good. You need to know the *public* address of the remote networks's gateway. And that's not all. You also need permission to pass through that gateway into the remote network.

Firewalls {#_firewalls}

Ideally, there are firewalls all around you even now. You don't see them (hopefully), but they're there. As technology goes, firewalls have a fun name, but they're actually a little boring. A firewall is just a computer service (also called a "daemon"), a subsystem that runs in the background of most electronic devices. There are many daemons running on your computer, including the one listening for mouse or trackpad movement, for instance. A firewall is a daemon programmed to either accept or deny certain kinds of network traffic.

Firewalls are relatively small programs, so they get embedded into most modern devices. One's running on your mobile phone, on your router, and your computer. Firewalls are designed based on network protocols, and it's part of the specification of talking to other computers that data packets sent over a network must announce specific pieces of information about itself (or be ignored). One thing that network data contains is a *port* number, which is one of the primary things a firewall uses when either accepting or denying traffic.

Websites, for instance, are hosted on web servers. When you want to view a website, your computer sends network data identifying itself as traffic destined for port 80 of the web host. The web server's firewall is programmed to accept incoming traffic destined for port 80, and so it accepts your request (and the web server in turn sends you the web page in response). However, were you to send, whether by accident or by design, network data destined for port 22 of that web server, you'd likely be denied by the firewall (and possibly banned for some time).

This can be a strange concept to understand because, like IP addresses, ports and firewalls don't really "exist" in the physical world. These are concepts defined in software. You can't open your computer or your router to physically inspect network ports, and you can't look at a number printed on a chip to find out your IP address, and you can't douse your firewall in water to put it out. But now you know that these concepts exist, you know the hurdles involved in getting from one computer in one network to another on different network.

Now it's time to get around those blockades.

Your IP address {#_your_ip_address}

I assume you have control over your own network, and that you're trying to open your own firewalls, and route your own traffic to permit outside traffic into your network. First, you need your local and public IP address. To find your local IP address, you can use the `ip` address on Linux:

$ ifconfig | grep "inet " inet 127.0.0.1 netmask 0xff000000 inet 192.168.1.6 netmask 0xffffffe0 [...​]

$ ipconfig

$ curl

http://icanhazip.com

93.184.216.34

$ firewall-cmd --permanent --zone=public \ --add-rich-rule 'rule family="ipv4" destination address="93.184.216.34" forward-port port=22 protocol=tcp to-port=22 to-addr=192.168.1.6'

$ sudo firewall-cmd --get-services amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc ceph cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns elasticsearch freeipa-ldaps ftp [...​] ssh steam-streaming svdrp [...​]

$ sudo firewall-cmd --add-service ssh --permanent

$ sudo firewall-cmd --add-port 22/tcp --permanent

Proxied content from gemini://sdf.org/klaatu/geminifiles/open-firewall.gmi (external content)

Gemini request details:

Original URL
gemini://sdf.org/klaatu/geminifiles/open-firewall.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.