LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-22-2020, 04:51 AM   #1
sllinux
Member
 
Registered: Feb 2009
Posts: 45

Rep: Reputation: 16
Cannot ping second IP address on another machine's virtual interface


I have an OpenVPN client connected to an OpenVPN server.

The server has the following routes:

Code:
default via 10.109.185.65 dev eth0 proto dhcp src 10.109.185.84 metric 100
10.8.0.0/24 dev tun0 proto kernel scope link src 10.8.0.1
10.109.185.64/27 dev eth0 proto kernel scope link src 10.109.185.84
10.109.185.65 dev eth0 proto dhcp scope link src 10.109.185.84 metric 100
The client has the following address on the tun0 virtual interface created by OpenVPN:

Code:
11: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 100
link/none
    inet 10.8.0.3/24 brd 10.8.0.255 scope global tun0
       valid_lft forever preferred_lft forever
    inet6 fe80::3c55:91d1:e8cf:7c55/64 scope link flags 800
      valid_lft forever preferred_lft forever
From the server, I can ping the client by doing "ping 10.8.0.3" and it works fine.

Then I added a second IP address to tun0 on the client by doing "ip addr add 10.100.1.2/24 dev tun0". It shows up on the tun0 interface as:

Code:
inet 10.100.1.2/24 scope global tun0
   valid_lft forever preferred_lft forever
On the server, I added a route for that subnet by doing "ip route add 10.100.1.0/24 dev tun0". It shows up in the route list as:

Code:
10.100.1.0/24 dev tun0 scope link
But trying a "ping 10.100.1.2" on the server failed.

Then I noticed that both the server and client had the following iptables FORWARD rule:

Code:
ACCEPT     all  --  10.8.0.0/24          anywhere
So I added another FORWARD rule for the 10.100.1.0 subnet by doing "iptables -A FORWARD -s 10.100.1.0/24" on both the server and client.

But trying a "ping 10.100.1.2" on the server still fails.

Is there anything else I need to do in order to be able to ping 10.100.1.2 from the server?
 
Old 08-22-2020, 05:26 AM   #2
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,855

Rep: Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149
I'm not quite sure why you're adding secondary IP addresses to the tun0 interface. However, I can explain that when wanting to reach subnets behind a given OpenVPN client, the 'iroute' directive is needed (as well as a route on the server)....

https://community.openvpn.net/openvpn/wiki/RoutedLans?
https://openvpn.net/community-resour...server-subnet/

Apologies if I'm on the wrong track here. I don't quite get your question.
 
Old 08-25-2020, 02:04 AM   #3
sllinux
Member
 
Registered: Feb 2009
Posts: 45

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by ferrari View Post
I'm not quite sure why you're adding secondary IP addresses to the tun0 interface. However, I can explain that when wanting to reach subnets behind a given OpenVPN client, the 'iroute' directive is needed (as well as a route on the server)....

https://community.openvpn.net/openvpn/wiki/RoutedLans?
https://openvpn.net/community-resour...server-subnet/

Apologies if I'm on the wrong track here. I don't quite get your question.
The reason I added a secondary IP address to tun0 is because there is a device connected to the client, and we want to access the device through the secondary IP address, not the 10.0.8.3 address.

I tried adding the following lines to server.conf:

Code:
route 10.100.1.0 255.255.255.0
push "route 10.100.1.0 255.255.255.0"
client-to-client
client-config-dir /etc/openvpn/server/ccd
I also added the following to the /etc/openvpn/server/ccd/client_name file:

Code:
iroute 10.100.1.0 255.255.255.0
The server is still not able to ping 10.100.1.2.

One strange thing I noticed is that on the server, OpenVPN created the following route:

Code:
10.100.1.0/24 via 10.8.0.2 dev tun0
10.8.0.2 is another OpenVPN client we have, but I want the 10.100.1.0 subnet to go through the 10.8.0.3 client. The /etc/openvpn/server/ccd/client_name file is for the 10.8.0.3 client, so why did OpenVPN create the route "via 10.8.0.2"? But even after I manually deleted that route and created a new route "via 10.8.0.3", the server still couldn't ping 10.100.1.2.

Last edited by sllinux; 08-25-2020 at 02:05 AM.
 
Old 08-25-2020, 02:26 AM   #4
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,855

Rep: Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149
Quote:
The reason I added a secondary IP address to tun0 is because there is a device connected to the client, and we want to access the device through the secondary IP address, not the 10.0.8.3 address.
That's not the solution. The tunnel address can be left out of the equation. Assuming that you have a device connected to the VPN client host eg via eth1 (with vtun0 tunnel via eth0), then you add a route to the device subnet from the server (and either a default route or static route back to the server from the client). For example...

server------INTERNET------eth0<client>eth1----192.168.4.0/24----device
vtun0=======tunnel=======vtun0

The client CCD file (configured in the server) should contain the following directive
iroute 192.168.4.0 255.255.255.0

The main server config file will contain...
route 192.168.4.0 255.255.255.0

As per the second link I gave...
Quote:
Why the redundant route and iroute statements, you might ask? The reason is that route controls the routing from the kernel to the OpenVPN server (via the TUN interface) while iroute controls the routing from the OpenVPN server to the remote clients. Both are necessary.

Last edited by ferrari; 08-25-2020 at 02:29 AM.
 
Old 08-25-2020, 10:49 AM   #5
sllinux
Member
 
Registered: Feb 2009
Posts: 45

Original Poster
Rep: Reputation: 16
Our network will actually look like this, because we will have multiple clients, each of which will have a device attached to it. There could end up being hundreds of clients on the right side.

Code:
device manager<10.8.0.2 client>---OpenVPN server---INTERNET---eth0/tun0<10.8.0.3 client>eth1---10.0.2.0/24---device<10.0.2.2>
                                               \---INTERNET---eth0/tun0<10.8.0.4 client>eth1---10.0.2.0/24---device<10.0.2.2>
                                               \---INTERNET---eth0/tun0<10.8.0.5 client>eth1---10.0.2.0/24---device<10.0.2.2>
So each device ends up being assigned the same 10.0.2.2 address on the client subnet. That's why we want to add a unique 10.100.1.x address to the tun0 interface on the client, so that the device manager can access each device.

So it wouldn't work to have "route 10.0.2.0 255.255.255.0" in the main server config file.

Last edited by sllinux; 08-25-2020 at 12:57 PM.
 
Old 08-25-2020, 02:35 PM   #6
ferrari
LQ Guru
 
Registered: Sep 2003
Location: Auckland, NZ
Distribution: openSUSE Leap
Posts: 5,855

Rep: Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149Reputation: 1149
I manage a network with a number of remote networks connected via tunnel routers. They generally all employ unique unique managed IP space. However, I have a couple of client situations whereby I have to use NAT to cope with internal/external addressing. You should be able to do the same here with suitable SNAT and DNAT rules in each of your clients.

Last edited by ferrari; 08-25-2020 at 02:49 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to create a virtual/clone interface to map to another existing interface ? Mac83 Linux - Networking 17 07-22-2019 03:14 PM
[CLOSE, DUPLICATE] Is it possible to create a virtual/clone interface to map to another existing interface ? Mac83 Linux - Networking 3 06-19-2019 12:26 AM
Ping between virtual interface on the same machine andre88 Linux - Networking 4 03-26-2019 02:44 PM
Can't Ping betwen interface on Virtual Machine nerka Linux - Networking 7 11-28-2011 12:39 PM
I cannot ping with command 'ping IP' address but can ping with 'ping IP -I eth0' sanketmlad Linux - Networking 2 07-15-2011 05:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 02:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration