Hey, welcome back my blog. Today I will be going through on how to setup a firewall for the DN42 network so that it can’t acces other stuff like the open web over the wireguard connections you open. It’s a really scuffed way of doing it but I’m just logging it here because I need to remember itself.
Setup
Install
Firstly we will want to go ahead and install UFW, to do this use one of the below command on your distro of choice.
|
|
Configure
Firstly we will want to go ahead and allow SSH connections to the server so that we don’t get locked out, to do this run the below command. We are also allowing the port range 50000-59999/udp these are the ports I use for my wireguard connections, you can change this to whatever you want.
|
|
Next we will want to go ahead and setup our script which we use to add connections, let’s walk through the below script. We start by asking for the interface name and then with that we get the endpoint IP so we can allow that. Then we allow all the DN42 and affiliate subnets and deny the rest.
|
|
Now when you have your wireguard connection setup just run ./firewall.sh and it will add the rules to the firewall. Be aware that if the IP of the peer ever changes you will need to run the script again. You could do this alot simpler but wheres the fun in that.
Now just run ufw enable and your done :D
Extra
So if you want to be able to redirect traffic via your network you can follow the below steps, this is a very scuffed way of doing it but I do it because I do not want to have BGP etc running on my router for DN42.
UFW Rules
Add the below to the bottom of your /etc/ufw/before.rules file, this will allow traffic to be redirected via your network. replace 10.0.0.0/8 with the subnet you want to be able to redirect from and the –to IP with your DN42 IP.
|
|
You will also need to allow connections from those through your firewall which can be done with the below command.
|
|
Finish
Now just setup a static route on your router to point the DN42 subnet to the machine your using as a router and your done. You can now redirect traffic destined for the DN42 network via your network.