Reply on same network interface (UDP) - linux

is it possible to reply all incoming packets/request on same network interface?
This is my setting: I have a headless Raspberry Pi (raspbian) with two network interfaces (eth0 and eth1). The fist interface (eth0) uses a public IP address, which is static. This interface is intended to provide access to the Pi (time- and web server, SSH) via the Internet. The second interface (eth1) uses the Raspberry Pi for general Internet connection (perform updates, sync own time or whatever) and uses a dynamic IP via DHCP. A general Internet connectivity over eth0 is not possible, so I have to use eth1 on the Pi.
My problem is that Internet (on the Pi) and the Internet access to the Pi are not working correctly.
first configuration (/etc/dhcpcd.conf):
interface eth0
static ip_address=141.41.241.68/28
static routers=141.41.241.65 192.168.0.1
after reboot 'ifconfig' shows the correct IP settings:
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 141.41.241.68 netmask 255.255.255.240 broadcast 141.41.241.79
...
eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.101 netmask 255.255.255.0 broadcast 192.168.0.255
...
result:
Internet on the Raspberry Pi (eth1): doesn't work
access to Raspberry Pi over Internet (via eth0):
SSH (TCP): works fine
Apache web server (TCP): works fine
NTP time server (UDP): works fine
Now I tried to change the metric of the interfaces, hoping that the change of prioritization is successful
second configuration (/etc/dhcpcd.conf):
interface eth1
metric 200
interface eth0
static ip_address=141.41.241.68/28
static routers=141.41.241.65 192.168.0.1
metric 201
result:
Internet on the Raspberry Pi (eth1): works fine
access to Raspberry Pi over Internet (via eth0):
SSH (TCP): doesn't work
Apache web server (TCP): doesn't work
NTP time server (UDP): doesn't work
Ok. I think all traffic going out to eth1 at default. With the tool 'iptraf-ng' I was able to see the problem:
TCP Connections (Source Host:Port) Iface
--------------------------------------------------
80.187.108.126:53024 eth0
141.41.241.68:80 eth0
141.41.241.68:80 eth1
80.187.108.126:53024 eth1
80.187.108.126:53025 eth0
141.41.241.68:80 eth0
141.41.241.68:80 eth1
80.187.108.126:53025 eth1
UDP Connections
--------------------------------------------------
UDP (76 bytes) from 80.187.108.126:28599 to 141.41.241.68:123 on eth0
UDP (76 bytes) from 192.168.0.101:123 to 80.187.108.126:28599 on eth1
We see:
On TCP: some connections going out to the wrong interface (eth1).
On UDP: The request from 80.187.108.126 came over eth0 and the response was sent over eth1.
Next, I defined the routing table to reply incoming packets on same network interface...
echo 100 public >> /etc/iproute2/rt_tables
ip rule add from 141.41.241.68/32 table public
ip route add default via 141.41.241.65 dev eth0 table public
result:
Internet on the Raspberry Pi (eth1): works fine
access to Raspberry Pi over Internet (via eth0):
SSH (TCP): works fine
Apache web server (TCP): works fine
NTP time server (UDP): doesn't work
and 'iptraf-ng' shows:
TCP Connections (Source Host:Port) Iface
--------------------------------------------------
141.41.241.68:80 eth0
80.187.108.126:52083 eth0
141.41.241.68:80 eth0
80.187.108.126:52084 eth0
141.41.241.68:80 eth0
80.187.108.126:52085 eth0
141.41.241.68:80 eth0
80.187.108.126:52086 eth0
141.41.241.68:80 eth0
80.187.108.126:52087 eth0
UDP Connections
--------------------------------------------------
UDP (76 bytes) from 80.187.108.126:28599 to 141.41.241.68:123 on eth0
UDP (76 bytes) from 192.168.0.101:123 to 80.187.108.126:28599 on eth1
We see:
On TCP: now it works correctly
On UDP: same problem :(
What can I do to send UDP responses over the correct interface (eth0)? I have no idea why TCP works fine but UDP fails :(
Its very frustrating and I have no more ideas.
I hope someone can help.
best regards,
SBond

Related

Can't access website in virtualbox after Windows 10 update

Host: Windows 10 (updated)
Guess: Ubuntu 14.04.5
Virtualbox: 5.2.12 r122591 (Qt5.6.2)
After the windows update I tried to access my virtual machine and it kept giving me random errors. After of dozens of tutorials and guides my current settings are:
Hosts file (on windows): 192.168.56.2 devserver
/etc/network/interfaces file(on ubuntu)(couldn't paste):
auto eth1
iface eth1 inet static
address 192.168.56.2
netmask 255.255.255.0
broadcast 192.168.56.0
auto eth0
iface eth0 inet dhcp
auto eth2
iface eth2 inet dhcp
Virtualbox network:
Attacked to: Host-only Adapter
Name: VirtualBox Host-Only Ethernet Adapter #3
Adapter Type: PCnet-FAST III (am79C973)
Promiscuous Mode: Allow All
MAC Address: 0800275A1DBB
But I still can't connect to the website. It keeps giving me the "page not found" message.
Solution
/etc/network/interfaces file
auto eth0
iface eth0 inet static
address 192.168.56.2
netmask 255.255.255.0
broadcast 192.168.56.0
hosts file
192.168.56.2 devserver

VM can't ping host that's two switches and a router away through NAT

I have a Linux VM (Kali) that's connected to a host only switch
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.40 netmask 255.255.255.0 broadcast 192.168.0.255
The Interface is up, the interfaces file looks like this
auto eth0
iface eth0 inet static
address 192.168.0.40
netmask 255.255.255
gateway 192.168.0.254
dns-nameservers 8.8.8.8
the switch is connected to an Ubuntu Server VM that has a masquerade NAT enabled to the 192.168.0.0/24 network and is connected via a bridged switch to the actual host, which is running Ubuntu 16.04
The NAT rule is on the POSTROUTING chain and it goes like this
Chain POSTROUTING (policy ACCEPT 20 packets, 1440 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- * ens33 192.168.0.0/24 0.0.0.0/0
and the interfaces file on the server machine looks like this
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens33
iface ens33 inet static
address 172.16.23.100
netmask 255.255.0.0
gateway 172.16.0.254
dns-nameservers 8.8.8.8
#iface ens33 inet dhcp
#Gateway for LAN1 - 192.168.0.0/24
auto ens38
iface ens38 inet static
address 192.168.0.254
netmask 255.255.255.0
The routing table on the host looks like this
default via 172.16.0.254 dev enp3s0
169.254.0.0/16 dev enp3s0 scope link metric 1000
172.16.0.0/16 dev enp3s0 proto kernel scope link src 172.16.0.6
Now i'm trying to ping the host from the Kali machine (from 192.168.0.40 to 172.16.0.6), but the ping isn't going through, i did tcpdump on the host machine on the only interface with 192.168.0.40 as the host but it doesn't pick up any traffic. the NAT rules aren't being used for some reason.
I can ping the default gateway and the server/router VM with Kali but the ping for the host doesn't go through. What am i doing wrong?
What i think should happen is that the packet goes through to the server through Kali's default gateway, once it's in the server machine it gets translated to ens33's address and from there it will go to the host and the host will send it back to ens33 because that should be the current source ip, but clearly that's not happening
I'm bad at paying attention to things, i put the NAT rule as eth33 instead of ens33, fixed it and it works now

SSH on Raspberry Pi3

I install "ubuntu-17.04-desktop-amd64" and "qt-opensource-linux-x64-5.8.0" on on my laptop.
I wrote an application with Qt 5.8 for windows. It works fine in windows and Ubuntu.
IP address of raspberry ("hostname -I"): 169.254.181.63
Enable SSH:
In raspberry: from Preferences menu of Rasbian.
In Ubuntu:
sudo service ssh status
....
.... Starting OpenBSD Secure Shell server.
.... Server listening on 0.0.0.0 port 22.
.... Server listening on :: port 22.
.... Started OpenBSD Secure Shell server.
I connect raspberry pi to laptop with Ethernet cable.
I create new device (Generic Linux Device) in "Tools -> Options…-> Devices tab"
Host name: 169.254.181.63
SSH port:22
Username: pi
Password: 1 (set by me)
Result test:
Device test: SSH connection: Network unreachable.
In Ubuntu:
ssh pi#169.254.181.63
ssh: connect to host 169.254.181.63 port 22: Network is unreachable
I edit the interface file to set the network configuration in raspberry:
sudo nano /etc/network/interfaces
Update:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.100.100
netmask 255.255.255.0
allow-hotplug wlan0
iface wlan0 inet manual
Update:
But after reboot raspberry and execute "hostname -I", I have "192.168.100.100 169.254.181.63"
You should configure a static IP in this way (see this link):
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.100.100
network 192.168.100.0
netmask 255.255.255.0
broadcast 192.168.200.25
You've to move address, netmask, etc. below the line iface eth0 inet static.
Check if your correct IP address is correct and use command in terminal. Open the terminal use this command and find the exact ip address:
cd /var/misc
cat misc
Copy this IP address and use this command:
ssh pi#ip_address
change the order. put the settings under iface eth0 not the lo.
iface eth0 inet manual
address 192.168.200.100
network 192.168.100.0
netmask 255.255.255.0
broadcast 192.168.200.25

Why are UDP packets sent from default interface address instead of the address where the client packet is received?

For a long time I had troubles using several software (early versions of Teamspeak 3, netcat, openvpn) communicating using UDP protocol. Today I identified the problem.
The main goal for me was to use openvpn over udp which did not seem to work on my server which has multiple ip addresses (runs Ubuntu Server Kernel 3.2.0-35-generic).
Using following config:
# ifconfig -a
eth0 Link encap:Ethernet HWaddr 11:11:11:11:11:11
inet addr:1.1.1.240 Bcast:1.1.1.255 Mask:255.255.255.224
...
# cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 1.1.1.240
broadcast 1.1.1.255
netmask 255.255.255.224
gateway 1.1.1.225
up ip addr add 1.1.1.249/27 dev eth0
down ip addr del 1.1.1.249/27 dev eth0
up ip addr add 2.2.2.59/29 dev eth0
down ip addr del 2.2.2.59/29 dev eth0
up route add -net 2.2.2.56 netmask 255.255.255.248 gw 2.2.2.57 eth0
# default route to access subnet
up route add -net 1.1.1.224 netmask 255.255.255.224 gw 1.1.1.225 eth0
Problem:
A simple tcpdump at the server reveals that udp packets (tested with netcat and openvpn) received at 2.2.2.59 are replied from 1.1.1.240 (client: 123.11.22.33)
13:55:30.253472 IP 123.11.22.33.54489 > 2.2.2.59.1223: UDP, length 5
13:55:36.826658 IP 1.1.1.240.1223 > 123.11.22.33.54489: UDP, length 5
Question:
Is this problem due to wrong configuration of the network interface or the application itself (OpenVPN, netcat)?
Is it possible for the/an application to listen on multiple ip addresses and reply from the interface address where it received the packet on UDP like it's doing when using TCP.
I know that you can bind applications for specific ip but that would not be the way to go.
I cannot see that this behaviour is due to the UDP protocol itself, since the application is possible to determine at which interface address the packet was received.
Specifically, openvpn has the --multihome option for handling this scenario correctly.

Virtual IP failover on 2 Linux box

I have 2 Linux VM Box.
VM1 ip is 192.168.0.4
VM2 ip is 192.168.0.5
GW: 192.168.0.1, net mask: 255.255.255.0
1)I have added a virtual ip on VM1
ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 up
Then I can ping it successfully from my client
2)removed the virtual ip on VM1
ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 down
Then I can NOT ping it successfully from my client
3)Add the same virtual ip on VM2
ifconfig eth0:1 192.168.0.10 netmask 255.255.255.0 up
!!I failed to ping this ip!!
however 1-2 hours later, I can ping it successfully.
3)Add the same virtual ip on VM2
however 1-2 hours later, I can ping it successfully.
Try flushing the ARP table on the client:
ip neigh flush all dev eth0
Also, I believe having the second VM send gratuitous ARPs after getting the new IP will solve the problem.

Resources