Ubuntu automatically connects to the virtual private network

Before we continue, an important assumption we made is that you already have a virtual private network client configuration file.
You can see an example Open Virtual Private Network client configuration file in our previous guide through the following link: Configure Open Virtual Private Network Client
on CentOS 8/UBin Figure 18.04

When the Ubuntu system starts, you can automatically connect to the virtual private network in two ways:

  • Run an open virtual private network client as a service.
  • Configure the network manager to automatically connect to the virtual private network using a specific network connection.

Install required packages

The following command installs the package we need to configure automatic virtual private network connection on Ubuntu.

apt install network-manager-open虚拟专用网络 network-manager-open虚拟专用网络-gnome open虚拟专用网络 open虚拟专用网络-systemd-resolved -y

Run the Open Virtual Private Network client as a service in Ubentu
When you install the package, it creates a directory where you can put the Open Virtual Private Network client configuration files. open虚拟专用网络/etc/open虚拟专用网络/client/
Therefore, please copy your Open Virtual Private Network configuration file to the Open Virtual Private Network client configuration directory. .conf.o虚拟专用网络
Please note that the configuration files in the directory should have a suffix. So if the original file is, rename it to the destination directory as shown below./etc/open虚拟专用网络/client/.conf.o虚拟专用网络.conf

sudo cp ~/gentoo.o虚拟专用网络 /etc/open虚拟专用网络/client/gentoo.conf

Run the Open Virtual Private Network client as a service
Once the client configuration file is in place, you will start the Open Virtual Private Network client service. Please note that this directory may contain multiple Open Virtual Private Network client configuration files.
Therefore, you can use this service to start your Open Virtual Private Network customer service with a specific configuration file placed on the directory. open虚拟专用网络-client@{Client-config}.service/etc/open虚拟专用网络/client/
Replace with the name of your Open virtual private network client configuration file, without the suffix or. {Client-config}.conf.o虚拟专用网络
For example, using the "Open Virtual Private Network" customer service, run the service as follows:gentoo.o虚拟专用网络

systemctl start open虚拟专用网络[email protected]

Check status:

systemctl status open虚拟专用网络[email protected]
 open虚拟专用网络[email protected] - Open虚拟专用网络 tunnel for gentoo
   Loaded: loaded (/lib/systemd/system/open虚拟专用网络[email protected]; indirect; vendor preset: enabled)
   Active: active (running) since Sun 2020-06-14 12:30:56 EAT; 5s ago
     Docs: man:open虚拟专用网络(8)
           https://community.open虚拟专用网络.net/open虚拟专用网络/wiki/Open虚拟专用网络24ManPage
           https://community.open虚拟专用网络.net/open虚拟专用网络/wiki/HOWTO
 Main PID: 5556 (open虚拟专用网络)
   Status: "Initialization Sequence Completed"
    Tasks: 1 (limit: 2315)
   CGroup: /system.slice/system-open虚拟专用网络\x2dclient.slice/open虚拟专用网络[email protected]
           └─5556 /usr/sbin/open虚拟专用网络 --suppress-timestamps --nobind --config gentoo.conf

Jun 14 12:30:57 amos open虚拟专用网络[5556]: ROUTE_GATEWAY 10.0.2.2/255.255.255.0 IFACE=enp0s3 HWADDR=08:00:27:4b:ff:18
Jun 14 12:30:57 amos open虚拟专用网络[5556]: TUN/TAP device tun0 opened
Jun 14 12:30:57 amos open虚拟专用网络[5556]: TUN/TAP TX queue length set to 100
Jun 14 12:30:57 amos open虚拟专用网络[5556]: do_ifconfig, tt->did_ifconfig_ipv6_setup=0
Jun 14 12:30:57 amos open虚拟专用网络[5556]: /sbin/ip link set dev tun0 up mtu 1500
Jun 14 12:30:57 amos open虚拟专用网络[5556]: /sbin/ip addr add dev tun0 10.8.0.2/24 broadcast 10.8.0.255
Jun 14 12:30:57 amos open虚拟专用网络[5556]: /sbin/ip route add 192.168.57.6/32 via 10.0.2.2
Jun 14 12:30:57 amos open虚拟专用网络[5556]: /sbin/ip route add 0.0.0.0/1 via 10.8.0.1
Jun 14 12:30:57 amos open虚拟专用网络[5556]: /sbin/ip route add 128.0.0.0/1 via 10.8.0.1
Jun 14 12:30:57 amos open虚拟专用网络[5556]: Initialization Sequence Completed

If you see this line, the initialization sequence is complete , then your virtual private network connection has been successfully established.
Check the specified address;

ip add s tun0
6: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 100
    link/none 
    inet 10.8.0.2/24 brd 10.8.0.255 scope global tun0
       valid_lft forever preferred_lft forever
    inet6 fe80::6b22:1d7f:5ef2:1db3/64 scope link stable-privacy 
       valid_lft forever preferred_lft forever

Enable the service to run when the system starts to ensure that the virtual private network connection is automatically started when the system starts.

sudo systemctl enable open虚拟专用网络[email protected]

Automatically connect to a virtual private network through the network manager
To be able to connect to a virtual private network using the network manager, make sure that you have created a virtual private network connection profile through the network manager.

Please follow the guide below to learn how to connect to the Open virtual private network server through the network manager:
Use the network manager on CentOS 8/Ubuntu 18.04 to connect to the Open virtual private network. The
Open Network Manager connection editor
click on the upper right corner of the Ubuntu system Connect icon and click " Edit Connection ".

You can also start the network manager connection editor by running the following command:

nm-connection-editor

This will open the connection editor wizard.
Insert picture description here
Select the network connection profile to activate the automatic virtual private network connection. For example, in my case, if I want to use the first Ethernet connection, Kifarunix , just select it and click on the settings gear at the bottom.
Insert picture description here
This opens the specific connection editor. Click on the " General " tab and choose to automatically connect to a virtual private network , and select the virtual private network connection profile you created earlier, in our case, it is gentoo .
Insert picture description here
Click " Save " to update the changes.

Verify this by opening and closing the connection. Please note that when you turn it on, the virtual private network connection will also be turned on.
Insert picture description here
Similarly, you can verify the same situation by restarting the system and checking the assigned virtual private network address.

Some texts are replaced by Chinese, you understand! ! !

Guess you like

Origin blog.csdn.net/KH_FC/article/details/114539418