How To Set Up A VPN Server On Ubuntu
How To Set Up A VPN Server On Ubuntu
Edit /etc/pptpd.conf file:
localip 192.168.0.1
remoteip 192.168.1.1-255
Edit /etc/ppp/pptpd-options file
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
proxyarp
nodefaultroute
lock
nobsdcomp
noipx ## you don't need IPX
mtu 1490 ## may help your linux client from disconnecting
mru 1490 ## may help your linux client from disconnecting
ufw Masquerading
IP Masquerading can be achieved using custom ufw rules. This is possible because the current back-
end for ufw is iptables-restore with the rules files located in /etc/ufw/*.rules. These files are a
great place to add legacy iptables rules used without ufw, and rules that are more network
gateway or bridge related.
The rules are split into two different files, rules that should be executed before ufw command line
rules, and rules that are executed after ufw command line rules.
a) 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”:
DEFAULT_FORWARD_POLICY="ACCEPT"
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
b) Now we will add rules to the /etc/ufw/before.rules file. The default rules only configure
the filtertable, 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:
The comments are not strictly necessary, but it is considered good practice to document your
configuration. Also, when modifying any of the rules files in /etc/ufw, make sure these lines are
the last line for each table modified:
First, since we trust pptpd completely, I would accept all traffic to/from my pptpd. I added this
lines at the beginning of the filter section.
Additionally, I must forward traffic to/from my pptpd. These lines was also added after the above
lines.
iptables Masquerading
iptables can also be used to enable masquerading.
a) Similar to ufw, the first step is to enable IPv4 packet forwarding by editing /etc/sysctl.conf and
uncomment the following line:
net.ipv4.ip_forward=1
net.ipv6.conf.default.forwarding=1
- Next, execute the sysctl command to enable the new settings in the configuration file:
sudo sysctl -p
- IP Masquerading can now be accomplished with a single iptables rule, which may differ slightly
based on your network configuration:
The above command assumes that your private address space is 192.168.0.0/16 and that your
Internet-facing device is ppp0. The syntax is broken down as follows:
The above commands will allow all connections from your local network to the Internet and all
traffic related to those connections to return to the machine that initiated them.
Logs
Firewall logs are essential for recognizing attacks, troubleshooting your firewall rules, and noticing
unusual activity on your network. You must include logging rules in your firewall for them to be
generated, though, and logging rules must come before any applicable terminating rule (a rule with
a target that decides the fate of the packet, such as ACCEPT, DROP, or REJECT).
If you are using ufw, you can turn on logging by entering the following in a terminal:
To turn logging off in ufw, simply replace on with off in the above command.
If using iptables instead of ufw, enter:
sudo iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j LOG --log-prefix
"NEW_HTTP_CONN: "
A request on port 80 from the local machine, then, would generate a log in dmesg that looks like
this: