VPS Setup at Binary Lane

Contents:
  1. Binary Lane
  2. Setup VPS User
  3. Generate ssh keys
  4. Prevent ssh Idle Timeouts
  5. Installing openvpn server on the VPS
  6. openvpn client
  7. iptables
  8. Backup and Restore iptables
  9. Tutorials on iptables
  10. iptables-persistent
  11. How to configure iptables for openvpn
  12. Rule Generator
  13. IP Tunnel
  14. How to setup OpenVPN on your VPS: Ubuntu 18.04
  15. How to install Webmin on Ubuntu 18.04
  16. Building A Raspberry Pi VPN
  17. Setting up VPN Gateway with Raspberry PI
  18. OpenVPN Setup on Ubuntu 18.04 Bionic Beaver Linux
  19. /home/glenn/glenn.ovpn
  20. pivpn
  21. TUN and TAP
  22. Private Network Space
  23. Classless Inter-Domain Routing

[Top][Home]

Binary Lane

Dashboard:
https://home.binarylane.com.au/services/servers

Administrative Login:
https://www.binarylane.com.au/mpanel/manage/server.lyonscomputer.com.au

[Top][Home]

Setup VPS User

Add user and give administration privileges and permissions:


[Top][Home]

Generate ssh keys

Generate ssh keys:


[Top][Home]

Prevent ssh Idle Timeouts

If SSH drops out after a minute or so of no activity it could be because the NAT functionality on the home/office router is aggressively closing inactive connections. If I run a script that prints the date every 30 secs the link stays up it is probably an idle timeout.

On client (your workstation) enable ServerAliveInterval as follows:


[Top][Home]


Installing openvpn server on the VPS

The Server is installed on the VPS Site.

Launch OpenVPN Access Server On Ubuntu:
https://openvpn.net/vpn-software-packages/ubuntu/ Output from the Install process above:


Try this https://linuxconfig.org/basic-ubuntu-22-04-openvpn-client-server-connection-setup

[Top][Home]

openvpn client

Install on a local Rpi or computer.

Connecting to Access Server with Linux:
https://openvpn.net/vpn-server-resources/connecting-to-access-server-with-linux/



[Top][Home]

iptables

Some iptables commands:


Managing ports on a Dedicated or VPS server is done through command line.
For example, if you were trying to open port 9999, the command to add that rule would be:


Flush All Rules, Delete All Chains, and Accept All Network Traffic:
Note: This will effectively disable the firewall. Only follow this section if you want to start over the configuration of your firewall.
First, set the default policies for each of the built-in chains to ACCEPT to ensure that we won’t be locked out from the server via SSH:


Ten, flush the nat and mangle tables, flush all chains (-F), and delete all non-default chains (-X) so
the firewall will now allow all network traffic and there will only the three default
chains (INPUT, FORWARD, and OUTPUT) remaining:


[Top][Home]

Backup and Restore iptables



[Top][Home]

Tutorials on iptables

  1. How the Iptables Firewall Works
    https://www.digitalocean.com/community/tutorials/how-the-iptables-firewall-works
  2. How To Set Up a Firewall Using Iptables on Ubuntu 14.04:
    https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-iptables-on-ubuntu-14-04
  3. Iptables Essentials: Common Firewall Rules and Commands:
    https://www.digitalocean.com/community/tutorials/iptables-essentials-common-firewall-rules-and-commands#saving-rules
  4. How To List and Delete Iptables Firewall Rules:
    https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules#flush-chains
  5. How To Set Up an Iptables Firewall to Protect Traffic Between your Servers
    https://www.digitalocean.com/community/tutorials/how-to-set-up-an-iptables-firewall-to-protect-traffic-between-your-servers
  6. A Deep Dive into Iptables and Netfilter Architecture
    https://www.digitalocean.com/community/tutorials/a-deep-dive-into-iptables-and-netfilter-architecture
  7. How To Test your Firewall Configuration with Nmap and Tcpdump
    https://www.digitalocean.com/community/tutorials/how-to-test-your-firewall-configuration-with-nmap-and-tcpdump



[Top][Home]

iptables-persistent

Note: Rules added to iptables are ephemeral. This application creates a new service called iptables-persistent that is configured to run at boot. This service will load the rules and apply them when each time the server is started.

If the firewall is updated you must save your iptables rules for them to be persistent.



[Top][Home]


How to configure iptables for openvpn


https://arashmilani.com/post?id=53



[Top][Home]

Rule Generator

Rules can be generated with an IPTables rule generator:
https://www.perturb.org/content/iptables-rules.html
Source: https://my.justhost.com/hosting/help/dedi-vps-manage-ports

[Top][Home]

IP Tunnel

Attach linux VPS as if it were on my local lan
https://serverfault.com/questions/202299/attach-linux-vps-as-if-it-were-on-my-local-lan

[Top][Home]

How to setup OpenVPN on your VPS: Ubuntu 18.04

https://lowendbox.com/blog/how-to-setup-openvpn-on-your-vps-ubuntu-18-04/

[Top][Home]

How to install Webmin on Ubuntu 18.04

Webmin is a web-based interface for system administration for Unix. Using any modern web browser, you can setup user accounts, Apache, DNS, file sharing and much more.

http://www.webmin.com/



How to install Webmin on Ubuntu 18.04:
Source:https://lowendbox.com/blog/how-to-install-webmin-on-ubuntu-18-04/

[Top][Home]


Building A Raspberry Pi VPN

Part One: How And Why To Build A Server:
https://readwrite.com/2014/04/10/raspberry-pi-vpn-tutorial-server-secure-web-browsing/

Part Two: Creating An Encrypted Client Side:

https://readwrite.com/2014/04/11/building-a-raspberry-pi-vpn-part-two-creating-an-encrypted-client-side/



[Top][Home]

Setting up VPN Gateway with Raspberry PI


https://www.raspberrypi.org/forums/viewtopic.php?t=96691
or
http://ozcan.com/blog/eng/setting-up-vpn-gateway-with-raspberry-pi/



vi /etc/openvpn/vpn.conf

The first line enables the use of external scripts to handle the DNS implementation tasks. The up and down lines are there to implement DNS servers pushed by the VPN server when the connection goes up, and afterwards to undo it, when the connection goes down.

Configuring iptables:

[Top][Home]


OpenVPN Setup on Ubuntu 18.04 Bionic Beaver Linux


https://linuxconfig.org/openvpn-setup-on-ubuntu-18-04-bionic-beaver-linux

ssh to VPS-Server wget https://git.io/vpn -O openvpn-install.sh

[Top][Home]

/home/glenn/glenn.ovpn

client
dev tun
proto udp
remote 112.213.34.215 1195
resolv-retry infinite
nobind
persis
persist-key
persist-tun
remote-cert-tls server
auth SHA512
cipher AES-256-CBC
ignore-unknown-option block-outside-dns
block-outside-dns
verb 3

-----BEGIN CERTIFICATE-----
MIIDQjCCAiqgAwIBAgIUQ+h/5D0ytmuTJPoX3vqIE7rDzCgwDQYJKoZIhvcNAQEL
BQAwEzERMA8GA1UEAwwIQ2hhbmdlTWUwHhcNMjAwMTIxMDgzNDI3WhcNMzAwMTE4
MDgzNDI3WjATMREwDwYDVQQDDAhDaGFuZ2VNZTCCASIwDQYJKoZIhvcNAQEBBQAD
ggEPADCCAQoCggEBANHz4ERhktFIanbuT4TFU2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qXsyqvo/j5mNnSlWCTb
gOaTHBBb5QKBgCffuTvsXEsfWLGnKQdEkjemQxv2GJ/+JBT53CXJlC6PTM0XmHna
cPPDYSJ73EriEvJvlu+wgkEnOzVDMhktjtMp2SNBuvRfRExKWspEiXDiPD7d3rcf
bTCRckIR43Lz97Y6koMTvmYoeNMBGNEg5rUXCWgSop1j6QsNJVzzq9JxAoGAZ4QQ
upFl8AmsTloT6aYWW9ThXbz/6YgcaZIxxnlJHZOo3INxZYAV6EMpcTSKOdIlRb9k
JWeFTE/UCBk7Hg/s8C+EIQ96In4mxu2w5mtabOVSEk1PsJVuhzrBIk6FGoajzpUX
xxshy7rtaaYgS/XPbRuU2qw29BIJZtbq8PdeN6UCgYA0dNuPriTwC5izcutIvT2S
XtxkKeda5jhrI9Bdz52INpzjlSSeYuRZvM+KRg9qkA7a7a/BPA1B3VgKCfMiPXd0
RvO9KdsVGSYVYYvLeHock1S1O33gtyat+RtzoODoDHxX3dDuPPEiELRDmA9pxjm7
NJiBbH0vUKp8HAvwmVvsuw==
-----END PRIVATE KEY-----


-----BEGIN OpenVPN Static key V1-----
935819e5401282627fa559cd7e6827a1
54e5096ae7a74080a68021d2de606981
0a075657a128a92620dbc7cc5bf95df5
a8b6be922b8b1e8c6b4eb33ec72e406d
9e966a8f5c13d5a60c47ba566cabeac1
1a5758d95d50ddd3603810a516fa6b1b
217ef2de7fca5edb029d184db1ed3138
bfd3ff732909e48293c05f93913a5ef6
a2bd51ed0a47c0a89a8bc86e5c70d6a7
a63c6f02fae970420bc39b1666f1f047
ae121df29f3e00e81b43ed9480cc5b9a
4f47ff869a15a433d6b9f4aaafaf8d09
e8deb327f47265734873b195f2ac8336
e03d710fc96cc2b2e3142c36c5a2abcf
71cfe547ff4154fa3195df6ff11763c1
0180ad70e052e42dc59f0be73281055d
-----END OpenVPN Static key V1-----



[Top][Home]

pivpn

PiVPN The simplest way to setup and manage a VPN in Rpi:

https://www.pivpn.io/

On Rpi R5:


[Top][Home]

TUN and TAP


https://en.wikipedia.org/wiki/TUN/TAP



[Top][Home]

Private Network Space

+---------------+-------------------------------+---------------------+--------------------+---------------+-------------+--------------+----------------+----------------------+
| RFC1918 name	| IP address range              | Number of Addresses | Largest CIDR block | Netmask       | Subnet Mask | Host ID size | Mask bits      | Classful Description |
| 24-bit block	| 10.0.0.0 – 10.255.255.255     | 16777216            | 10.0.0.0/8         | (255.0.0.0)   | 24 bits	 | 8 bits	    | single         | class A network      |
| 20-bit block	| 172.16.0.0 – 172.31.255.255   | 1048576             | 172.16.0.0/12      | (255.240.0.0) | 20 bits	 | 12 bits	    | 16 contiguous  | class B networks     |
| 16-bit block	| 192.168.0.0 – 192.168.255.255 | 65536	              | 192.168.0.0/16     | (255.255.0.0) | 16 bits     | 16 bits	    | 256 contiguous | class C networks     |
+---------------+-------------------------------+---------------------+--------------------+---------------+-------------+--------------+----------------+----------------------+

https://en.wikipedia.org/wiki/Private_network



[Top][Home]

Classless Inter-Domain Routing

Classless Inter-Domain Routing (CIDR) is a method for allocating IP addresses and IP routing. IP addresses are described as consisting of two groups of bits in the address:

  1. the most significant bits are the network prefix,
    which identifies a whole network or subnet, and
  2. the least significant set forms the host identifier

Source: https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing [Top][Home]
Glenn Lyons VK4PK
glenn@LyonsComputer.com.au
Ver:gnl2019mmdd - pre published v0.9