Ubuntu 18.04. I have been given a requirement to use Ubuntu as a simple router.
The Ubuntu box has 2 interfaces - ens33 DHCP, ens38 192.168.10.1/24. 33 is outside, 38 is inside for my purposes. There are a couple of networks behind this box - 192.168.10.x and 192.168.20.x. From any of these networks, I can ping both the interfaces on the ubuntu box. I cannot ping out past the external interface (33).
I have edited /etc/sysctl.conf to allow ipv4 forwarding - net.ipv4.ip_forward=1.
I have added a route to show gateway to other network 192.168.20.x via 38.
Not looking to nat, just route.
Anyone see what I'm missing? Let me know if more information is needed.
Doug
Wanted to post the answer I was looking for in case anyone else needs the same scenario. AlexP pointed me in the right direction above - the outside boxes didn't know how to reply back and I didn't want to have to add routes on every network that may use this.
I did want routing but I also needed NAT.
These instructions were cobbled together from several different sources but primarily - https://help.ubuntu.com/lts/serverguide/firewall.html <- the ufw IP Maquerading section here.
CentOS instructions from here- https://ronnybull.com/2015/11/20/how-to-centos-7-router/.
I am assuming an internal and an external interface on the Ubuntu box and that the settings for those have already been configured. (Also added instructions at the very bottom to accomplish the same thing with CentOS 7 - that was also a requirement of mine)
1. first, enable ufw and ufw logging
2. Flush any existing rules (do NOT do this if you are already using ufw or IP tables for firewalling). Delete and flush. Default table is "filter". Others like "nat" must be explicitly stated.
3. First, packet forwarding needs to be enabled in ufw. Two configuration files will need to be adjusted, in /etc/default/ufw change the DEFAULT_FORWARD_POLICY to “ACCEPT”:
4. Then edit /etc/ufw/sysctl.conf and uncomment:
5. Now add rules to the /etc/ufw/before.rules file. The default rules only configure the filter table, and to enable masquerading the nat table will need to be configured. Add the following to the top of the file just after the header comments:
For each Table a corresponding COMMIT statement is required. In these examples only the nat and filter tables are shown, but you can also add rules for the raw and mangle tables. In the above example replace eth0, eth1, and 192.168.0.0/24 with the appropriate interfaces and IP range for your network.
6. Finally, disable and re-enable ufw to apply the changes:
IP Masquerading should now be enabled. You can also add any additional FORWARD rules to the /etc/ufw/before.rules. It is recommended that these additional rules be added to the ufw-before-forward chain.
CentOS 7 firewalld config to accomplish the same thing -
1. Enable IPv4 packet forwarding.
a. Add the following to /etc/sysctl.conf:
b. Apply the sysctl settings:
2. Add direct rules to firewalld. Add the --permanent option to keep these rules across restarts.
a. Add the following to /etc/sysctl.conf:
b. Apply the sysctl settings:
2. Add direct rules to firewalld. Add the --permanent option to keep these rules across restarts.