Multicast Routing over Wlan and Eth0 interface - linux

I want to make my Raspberry PI model 3 as a router that is as follows -
Computer will be connected to RPI via Ethernet (eth0) interface
Phone will be connected to RPI over Wifi (wlan0) interface.
I was able to setup a interfaces with the help of the following links -
https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/
But I am not able to do the multicast routing from wlan0 to eth0 (or) vice versa Can you please help me with it. I need to route bonjour packets over the interfaces.
Note:
both the interfaces wlan and eth are supporting MULTICAST ( verified with ifconfig command ) I was able to get UP BROADCAST RUNNING MULTICAST for both the interfaces.
I have tried using the following commands for multicasting -
route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
route add -net 224.0.0.0 netmask 240.0.0.0 dev wlan0

You can use avahi-daemon to reflect mDNS queries between interfaces. Some basic configuration like this in avahi-daemon.conf should be enough:
[server]
use-ipv4=yes
use-ipv6=yes
enable-dbus=no
allow-interfaces=eth0,wlan0
[publish]
disable-publishing=yes
[reflector]
enable-reflector=yes

This is quite an old discussion but I tried the given answer and it broke LAN DNS, so don't do it. Instead, edit file:
nano /etc/avahi/avahi-daemon.conf
change this one line to ‘yes’:
enable-reflector=yes
restart the service:
service avahi-daemon restart
check to see if the ports are detected automatically:
systemctl status avahi-daemon.service
Takes a minute for new services to be discovered and appear. Works on Buster. The app Discovery (formerly Bonjour Browser) is helpful to verify mDNS ZEROCONF multicast packets are getting across. Also there's an iOS app.

Related

How to change default interface for internet?

I have a PC with Ubuntu server 18.04 installed on it and I'm trying to use this PC as a server. There are 2 interfaces involved here:
To provide It's internet, I am using an android smartphone that has access to internet via it's Data and it will be sharing internet with my PC (server) via USB Tethering. This will create an interface called 'enp0s29f7u8'. This interface will get an IP automatically (DHCP?), mostly '192.168.42.249'.
There is another interface called 'enp2s0' which is a Huawei internet modem and it's connected to my PC with a LAN cable. This 'enp2s0' will serve as an Access-Point so I can SSH to my PC While I'm close. I installed 'ifupdown' on server so I can assign an Static IP to my Access-Point, namely '192.168.1.10'.
$ cat /etc/network/interfaces
auto enp2s0
iface enp2s0 inet static
address 192.168.1.10
netmask 255.255.255.0
network 192.268.0.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
Here is the problem: I cannot access internet with this setups. It's like Ubuntu is trying to connect to Internet via 'enp2s0', which is only an AP with no access to internet.
So i tried
sudo ifconfig enp2s0 down
and there it is, i have internet. Also, when I do
sudo ifconfig enp2s0 up
after that, i still have access to internet.
How can I config my PC so that it will always use 'enp0s29f7u8' to access internet and use 'enp2s0' only as an AP?
p.s. 1: I really don't understand network stuff. I tried changing default gateway (I don't know why) but it didn't helped(at least the way i did).
p.s. 2: I'm not a native English speaker. Hope that I could talk my mind.
To modify the routing table you have to use the command route.
If you run the command as super user it should show how the traffic is routed from your host. You have to change the default to enp0s29f7u8. In order to change it you can simply remove the default
# route del default
and add again
# route add default dev enp0s29f7u8
You can route only some address to the other interface. Have a look at the man for more option of the route command

Two wired connection at the same time

I am struggling with a network problem.
My computer needs to be linked to two differents networks. one via PCI the other one via a USB adapter. The pci is the "usual" network, the usb is to use for specific address.
I have tried differents solutions, with dns, multiple wired connection, modifiying /etc/network/interfaces, ...
But I can't manage to have the 2 networking working at the same time.
Do you have any solution. I am working with Debian - jessie.
Cheers
Since you haven't specified any networks, IP addresses or device names, I will use my machine as an example.
I have an IOGear ethernet USB dongle which shows up as device enx0050b6d341bb, and an RTL811 PCI ethernet device which shows up as eth0. eth0 is plugged into the "main" network which has a DHCP server and enx0050b6d341bb is connected to a private switch on my workbench.
If I want to use eth0 to connect to the internet, but use enx0050b6d341bb to connect to anything on network 192.168.168.0/24, /etc/network/interfaces will look like this:
auto lo
iface lo inet loopback
# Obtain DHCP address from server
auto eth0
iface eth0 inet dhcp
# Connect to 192.168.168.0 network
auto enx0050b6d341bb
iface enx0050b6d341bb inet static
address 192.168.168.3
network 192.168.168.0
netmask 255.255.255.0
Since I only have one device using DHCP, my default route will automatically go through that device, which happens to be exactly what I want :-)
solargy#GEPY633007AX:~$ ip route
default via 192.168.10.1 dev eth0
192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.67
192.168.168.0/24 dev enx0050b6d341bb proto kernel scope link src 192.168.168.3
The above shows that my default traffic will go through eth0 and that any traffic for addresses in network 192.168.168.0/24 will go through enx0050b6d341bb. To verify that, you can find out which device will be used to communicate with address 192.168.168.2:
solargy#GEPY633007AX:~$ ip route get 192.168.168.2
192.168.168.2 dev enx0050b6d341bb src 192.168.168.3
cache
As you can see, any traffic for 192.168.168.2 will go through enx0050b6d341bb.

Raspbian : Force a wlan0 static ip [closed]

Closed. This question is not about programming or software development. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 6 months ago.
Improve this question
I would like to configure a wlan0 static ip and connect through it by ssh.
Here my /etc/network/interfaces :
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
adress 192.168.0.2
netmask 255.255.255.0
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.100.102
netmask 255.255.255.0
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
When I do ifconfig my wlan0 and eth0 interfaces are correctly configured :
However, when I want to ssh my raspberry by wifi, my Wifi router give to my raspberry the ip : 192.168.100.116.
How can I force my Wifi router to give 192.168.100.102 to my rapsberry pi ?
Moreover, My Wifi router give to my raspberry sometimes 192.168.100.102 and sometimes 192.168.100.116
Don't know why
I experienced similar issues when I wanted to connect my Rasperry Pi 2 with Raspbian Jessie Lite in a headless configuration for access using SSH from my Windows 10 PC with PuTTY.
In my case it turned out that the Ahavi daemon (an implementation of zeroconf) conflicted with the DHCP and name server options of my router.
Raspbian Jessie and Raspbian Jessie Lite comes pre-configured with an Avahi and a DHCP client deamon for automated network configuration. In most situation this will probably work fine, but if not, things take a turn for the worse with unpredictable side-effects.
Instead of going too deep into any details (its really a long story) I will just summarize here what I did and why. There are too many possible issues and I dont want to push you into the wrong direction. Try it out. If it fails, look for another approach or leave a comment for clarification.
Now let's get your feet wet:
Try it first on a non-productive SD card with a fresh copy of Raspbian Jessie (for headless servers I prefer Raspbian Jessie Lite).
Start the Raspberry Pi with a keyboard and a monitor connected and login with user pi.
Start raspi-config with sudo raspi-config and make sure to turn on the SSH server (menue 7 Advanced Options -> A4 SSH).
Get your current IP address for eth0 with ifconfig.
Try to connect to this address over ethernet using ssh. In case you cant connect, resolve this issue first. You cant connect over WLAN at this stage.
In case your connection succeeds, you can do the rest of your configuration using this connection over ssh.
Purge the avahi-daemon
$ sudo apt-get purge avahi-daemon
Dont worry about the error message 'rmdir: failed to remove ‘/var/run/avahi-daemon’: Directory not empty'. This is related to a an empty socket and a pid file, that currently cannot be removed. You can ignore this message or remove the directory manually, but it wont hurt in case you just leave it.
$ sudo rm -r /var/run/avahi-daemon
Configure /etc/network/interfaces
It's important to know, that we need only one single change in this file. Open /etc/network/interfaces for changes with the editor of your choice (note: if you followed this steps 1:1 extended vim is not yet installed).
$ sudo nano /etc/network/interfaces
Add the line auto eth0 just before the existing line iface eth0 inet manual. That's all we have to do here is to here. After the changes the file should look like this:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Note: make sure to read and to understand the comments on top of the file!
Configure the DHCP client daemon
Next, as stated in the comments of the previously edited file, add the static ip configuration at the end of the configuration file for the DHCP client daemon.
It might sound silly to use a DHCP client if we are going to use static IP addresses anyway. However, when I tried to remove the DHCP client daemon I experienced new configuration and/or dependency issues. Finally I decided to keep as close to the standard configuration as possible and leave it as is.
The configuration is done at the very end in the file /etc/dhcpcd.conf (watch proper spelling). The last line in the file should read: 'nohook lookup-hostname'. So let's open the the file in the editor and scroll down to the bottom of the file.
$ sudo nano /etc/dhcpcd.conf
Add there the static ip definition. In my case the definitions at the of /etc/dhcpcd.conf look like this:
nohook lookup-hostname
# static ip configuration for eth0 and wlan0
interface eth0
static ip_address=192.168.1.61/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
interface wlan0
static ip_address=192.168.1.62/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8
Note that the syntax is different from the syntax used in /etc/network/interfaces. For a full class C network the netmask must be provided in form of a /24 at the end of the IP address. For further details consult man dhcpcd.conf.
Reboot and test your configuration with eth0
After the next reboot you should have a reliable network configuration with static ip addresses. But remember, we are not yet finished and only eth0 will work. At this point even no IPv4 address will be shown for wlan0 if ifconfig is issued
In case it fails and you didn't do anything wrong so far (carefully check for typos), then you have another issue that must get fixed first; in this case this solution is probably not for you.
Configure WLAN
To configure WLAN we have to edit /etc/wpa_supplicant/wpa_supplicant.conf and add a network configuration to it.
In my case I'm using WPA/PSK for secure access and after modifying the country code and adding the network entry, the content of the file looks something like this:
country=CH
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
# home network; allow all valid ciphers
network={
ssid="home"
scan_ssid=1
key_mgmt=WPA-PSK
psk="very secret passphrase"
}
ssid="home" is the WLAN network name (SSID) of the WLAN router or access point.
scan_ssid=1 scans for hidden SSID's. This is usual practice but can slowdown the scan process.
key_mgmt=WPA-PSK defines that WPA pre-shared key management protocol will be used.
psk="very secret passphrase" defines your passphrase to access the router.
Replace the values assigned for ssid and psk with the real values for your secure WLAN access. There are several supported protocols, some requiring other and more options.
Consult man wpa_supplicant.conf for additional and more detailled information.
Reboot and test your configuration with wlan0
Now it's time to reboot and test wlan0. The ip address configured for wlan0 should now appear if ifconfig is issued.
If this is the case you should be able to access the Rasperry Pi using ssh with the IP address configured for wlan0.
I hope you are happy and everything works fine for you so far. If this is the case, I could stop writing here and leave you alone. But wait, there is more!
Two network connections, does that make sense?
If you connect to the Raspberry Pi from the same network over both, eth0 and wlan0 and issue an ifconfig to take a look at the transmitted and received packets or bytes, you will recognize, that even you connected to the IP for wlan0 most traffic is going through eth0.
I cant explain why this is the case, but obviously somehow the packets are routed along the faster path which sounds good so far.
However, I've seen rare situations where this behaviour was undesirable and slowed my connections down. Since I'm using my Raspberry Pi either near my router using a wired connection to eth0 or more distant from the router with no access to a cable using wlan0, I decided to stop wlan0 if a cable with an active connection to the router is attached to eth0.
To do this I created the script /home/pi/ifdown-wlan-if-not-needed.sh
#!/bin/sh
#### Shutdown wlan0
# Test eth0 for a cable attached and
# shutdown wlan0 if this is the case.
###
sleep 30
cable=$(cat /sys/class/net/eth0/carrier)
echo $cable
if [ "$cable" = "1" ]; then
sudo ifdown wlan0
fi
exit 0
Then I've set the script to executable
$ chmod +x /home/pi/ifdown-wlan-if-not-needed.sh
And added it for execution after reboot with crontab -e to the crontab of user pi.
#reboot /home/pi/ifdown-wlan-if-not-needed.sh
Name to IP address resolution
So far I have not yet addressed the name to IP address resolution problem. How this can be done best, depends on your network equipment and use case.
My router provides the ability to bind names to MAC addresses, hostnames and IPv4 adresses. However, for some reason none of these options really work. Some times it works by simply using the given name, other times the suffix .home is needed. Sometimes the names disappear from the list or no name resolution takes place even everything looks ok.
I finally defined the adresses in the C:\Windows\System32\drivers\etc\hosts file of my Windows PC and my Notebook. This is certainly not state of the art but works reliable and without hassle.
However, I cant guarantee that what I did works for you too, but I hope it brings you on the right track to get your problem solved. I've been using my configuration since the release of Raspbian Jessie about one year ago. It survived any updates without hassle so far.
Good luck!
Login on your router management interface and (if it has this feature, most do have it) reserve a DHCP address on the router for your selected client, so that the specific client always has the same IP address. See this article for more information.

Soft Access Point/Client Connect using wpa_supplicant with 2.4/5Ghz channels

This is a weird one. Let me start with that.
I am currently working on a Yocto embedded linux board from Digi, if that matters. I have just managed to, through use of dnsmasq and wpa_supplicant, allow other devices to connect to the board.
My current question is this: Can I use the 5.0 Ghz channel for allowing other devices to connect, and the 2.4Ghz channel to allow for the board to connect to other wifi access points?
My configurations:
#dnsmasq.conf
interface=wlan0
dhcp-range=10.0.0.10,10.0.0.200,2h
#interfaces
auto wlan0 inet static
address 10.0.0.1
netmask 255.255.255.0
wpa_driver nl80211
wpa_conf /etc/wpa_supplicant.conf
#wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
fast_reauth=1
update_config=1
#Soft AP Mode
ap_scan=2
network={
ssid="mySSID"
mode=2
frequency=2412
key_mgmt=WPA-PSK
proto=RNS
pairwise=CCMP
psk="MySecret"
}
Does anyone has an idea (or better yet, an improved version of what I'm doing) of how to get it to do this?

Multiple NIC card with different subnet

Am using Cent OS 6.2 (64bit), I have 4 NIC interface, in that am trying to connect two NIC with different subnet,
em1 with 10.30.2.x series
em4 with 10.30.4.x series
Also I added route with /sbin/route add -net 10.30.4.0 netmask 255.255.255.0 dev em4
When I make the network device up "ifup em4" am not able to ping both the interfaces.
There is no IPtables running and selinux also disabled.
The same setup is working in one more DELL server, in that server reverse IP and IP forwarding is not enabled, even then its working.
Reverse IP & IP Forwarding
cat /proc/sys/net/ipv4/conf/em2/rp_filter
1
cat /proc/sys/net/ipv4/ip_forward
0
Any comments would be appreciated.
Thanks in advance.
If you are sure that ip addresses are actually setted on the interfaces, everything should work out, i would suggest to check network equipment on the way.
easiest way to test this is to use tcpdump -i any icmp and see if you actually receive the packets, this will also show you if your pong is going on the wrong interface.
hope that helps

Resources