How to set up autoip with local-link (RNDIS) on linux and embedded linux - linux

I'm trying to figure out how to automatically setup an zeroconfig network address on a RNDIS Usb Gadget.
currently when i plug in the device, on the device i have to
$ modprobe g_ether
$ ifconfig usb0 up
$ avahi-autoipd usb0 &
and on the host i have to
$ avahi-autoipd usb0 &
they'll both get a 169.x.x.x number and I can ping, sometimes it doesn't work though. The device does not have a NetworkManager, we use busy box to start, I'm sort of looking at this as a possible solution Static Host RNDIS IP by linux based USB Gadget device, but I'd prefer to use local ip's.
A long time ago i some vague instructions on how to set a script to run in /etc/network/interfaces when a interface becomes available, but i'm having a hard time finding that again.
Thanks!

I figured it out, in /etc/network/interfaces
allow-hotplug usb0
iface usb* inet manual
up /usr/sbin/avahi-autoipd --force-bind -D $IFACE
down /usr/sbin/avahi-autoipd --kill $IFACE

Related

Remove DNS from device using `nmcli`

I want to remove the DNS currently associated to the device and add a new one using nmcli
So, if I do nmcli device show eth0 I can see
IP4.DNS[1]: 10.0.2.2
If I do sudo nmcli device modify eth0 ipv4.dns "8.8.8.8"
then I can see
IP4.DNS[1]: 10.0.2.2
IP4.DNS[2]: 8.8.8.8
but I want to remove the first one. How can I do it? If i try sudo nmcli device modify eth0 ipv4.dns "" then the second one (8.8.8.8) is removed but the first one is still there.
My final goal is to set ONLY 8.8.8.8 (for example...)
EDIT:
I am a bit confused between connection and device.
For example, let's say that I had 10.0.2,2 and I had 8.8.8.8 using one of these two commands:
nmcli connection modify netplan-eth0 ipv4.dns 8.8.8.8
nmcli device modify eth0 ipv4.dns 8.8.8.8
Because it seems there is a device and then there is a connection bound to it, so I can modify the dns using one of these two commands.
Now, I can see:
Using nmcli device show I have in the result
IP4.DNS[1]: 10.0.2.2
IP4.DNS[2]: 8.8.8.8
but using nmcli connection show netplan-eth0 I can see only
ipv4.dns: 8.8.8.8
So, my problem now is that I can easily modify the only dns in the connection, that is 8.8.8.8 using one of the followin command:
nmcli connection modify netplan-eth0 -ipv4.dns 8.8.8.8
nmcli device modify eth0 -ipv4.dns 8.8.8.8
BUT, I don't know how to remove the 10.0.2.2 that is showing only in the device but not in the connection.
BTW I did not set manually 10.0.2.2, I suppose it was taken through dhcp. And for some motivation this dns is bound only to the device but not to the connection.
With these details the problem should be more clear :)
For the general way to modify the dns, look at the answer of missconfigured.
About the problem of the dns get through netplan or dhcp, I could remove them using the following command:
nmcli device modify eth0 ipv4.ignore-auto-dns yes
After that, I was able to remove the 10.0.2.2 dns.
To the Answer,
The below command is able to remove the default DNS, but after restart NetworkManager, the default DNS comes back. How to make it permanent? Thanks.
nmcli device modify eth0 ipv4.ignore-auto-dns yes

Check NetworkManager is DHCP or Static with command line Ubuntu

How can I check the GUI network setting is set DHCP or Static with command line? for the active and connected interface in Ubuntu 18.04
I want one line command like grep give me static/dhcp or true/false
Can use ip command to check interface you're interested in.
E.g. to check the interface eth0:
if ip -6 addr show eth0 | grep -q dynamic; then
echo "Uses DHCP addressing"
else
echo "Uses static addressing"
fi
-6 option is for checking IPv6 interface. You can use -4 for IPv4.
nmcli -f ipv4.method con show
If the output is auto, then it is DHCP.
If the output is manual, then it is static.
or
cat /etc/network/interfaces
DHCP enabled
auto eth0
iface eth0 inet dhcp

Forward ethernet packets in other network and back

i have a networking problem i was hoping to get some answers here. So i have multiple raspberry pi that all have wifi connectivity and ethernet. All the PIs are connected to a network via wifi, and on ethernet to each other. what i need is this: if a raspberry has a problem with the wifi(no signal or smth) i want to send that package over the ethernet and another raspberry should pick up that package on ethernet and forward that on it's owm wifi interface further. Could anybody give me some hints on how this should be approached? Any help would be much appreciate.
you'll have to enable routing in each pi, using sysctl, then enable dynamic routing on each pi, be it ospf or rip does not matter in your case, but you'll have to stick with your choice with the other pis, otherwise you will need to do more complex configuration.
i strongly suggest that you try to set it up yourself by reading the man, you'll get a feeling of satisfaction when you do it, i'm sure.
edit 1 : each pi will be a router, having 2 interfaces,2 ethernet connected pis should belong to the same subnet of course.
edit 2: when a wifi link is down, a raspberry will use the ethernet, the next pi must use nat to translate the packets so they can reach the public network.
example : wlan0 is external, eth1 is internal
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -i eth1 -o wlan0 -j ACCEPT
edit 3: Setting up ospf
first, install quagga on each router(pi)
edit /etc/quagga/daemons and replace no by yes in the lines zebra and ospf then do this
cd /etc/quagga
cp /usr/share/doc/quagga/examples/zebra.conf.sample .
mv zebra.conf.sample zebra.conf
do the same for ospfd.conf and vtysh.conf
let the fun begin : here is an example on how to do it
vtysh
conf t
router ospf
network 10.0.1.0/24 area 1
network 192.168.1.0/24 area 1
end

Linux WiFI AP : refresh `iw dev wlan0 station dump` output (inactive time)

I have a Linux (3.14.36) embedded board acting as a WiFi AP.
The WiFi chipset doesn't support monitoring mode.
My laptop(the client) is connected to this board by WiFi
The WiFi AP is acting as a network bridge to another computer, and doesn't provide an IP adress to the client (the WiFi AP only has the MAC address of the client)
I want to monitor the signal strengh of the connection WiFi AP <-> Client and be able to trigger a "refresh" of the signal strengh value.
Doing : iw dev wlan0 station dump gives me :
Station xx:xx:xx:xx:xx:xx (on wlan0)
inactive time: 123820 ms // <-- The problem
rx bytes: 10291
rx packets: 60
...
signal: -65 dBm // What I want to refresh
...
I understood that the signal strengh is updated every time there is a network activity. (So, in the example above, it has been refreshed 123s ago).
How can I force a refresh of this value ? (By forcing the AP to send "something" to the client for example) Knowing that the board/WiFi driver/WiFi device doesn't support tools such as iwconfig
For anyone finding this thread now:
I had this issue and my solution was to ping the device before doing the iw dump, e.g.
Get the list of of connected MAC addresses:
iw dev wlan0 station dump | grep 'signal' | awk '{print $2}'
Then get the IP address from these MAC addresses (alternatively you could use arp):
ip neigh | grep 'ma:ca:dd:re:ss:ss' | awk '{print $1}'
Then ping each of those:
ping -c 1 'IP.address'
Then get the refreshed signal for that MAC address
iw dev wlan0 station get 'ma:ca:dd:re:ss:ss' | grep 'signal' | awk '{print $2}'
I wrapped all this up in a Python script and it seemed to give reliable data.
I'll give it a try:
You're embedded so I guess you have busybox. You have no IP but you may then use arping (if this applet is not configured in your busybox build, change the config) to send something small and useless that may wake up the thing. What IP to use for your ARP requests? Well it seems you can use a "dummy" IP.
I'm running this on a PC but I do have busybox with its arping, and I use a wired interface, but here is the concept:
jbm#sumo:~/sandbox/iw$ sudo busybox arping -w 1 -U -I eth0 0.0.0.0
ARPING to 0.0.0.0 from 192.168.1.66 via eth0
Sent 2 probe(s) (2 broadcast(s))
Received 0 reply (0 request(s), 0 broadcast(s))
The useful thing is that though the "dummy" IP, I can check with tcpdump that the arp requests do actually go on the wire (or in the air in your case):
jbm#sumo:~$ sudo tcpdump -i eth0 -v arp
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
10:42:20.111100 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 0.0.0.0 (Broadcast) tell sumo, length 28
10:42:21.111206 ARP, Ethernet (len 6), IPv4 (len 4), Request who-has 0.0.0.0 (Broadcast) tell sumo, length 28
^C
2 packets captured
2 packets received by filter
0 packets dropped by kernel
So sending ARP request on your wireless interface may be enough to "wake up" your connection and refresh your RSSI.
EDIT:
See the interesting uses and properties of IP 0.0.0.0 here:
https://en.wikipedia.org/wiki/0.0.0.0
EDIT 2:
Re-thinking about it, I realized there will be a problem if your wireless interface does not have an IP itself. Which, if I'm not mistaking, may not necessarily be case in your bridging configuration. In such case, arping will not have a source address to build its request packets (nor will know how to listen for responses), and will fail.
But you can create your own "mini-unidirectional arping", using an AF_PACKET socket and build your own ARP request packet with a dummy/random source IP address. It will be unidirectional because the response to your forged ARP request, if any, would go to to the random source IP which may and preferably should not exist. But it the principle of just awaking your wireless connection by sending "something", that may do the trick.
For inspiration on how to code this "mini-unidirectional arping", have a look at busybox implementation from its udhcpc/udhcpd (it's simpler than the full-blown arping busybox applet):
https://git.busybox.net/busybox/tree/networking/udhcp/arpping.c#n38
The from_ip parameter is what you want to forge. You can use your actual MAC as from_mac, just for the sake of dignity :-) You don't even have to wait for a response (starting line 89), so that would be something like 50 lines of C code + a little main if you want to add a few options to it.

How do I restart wlan0 with the static ip instead of a dynamic ip? [closed]

Closed. This question does not meet Stack Overflow guidelines. 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 7 years ago.
Improve this question
I have a Raspberry Pi running Raspbian Wheezy. The /etc/network/interfaces is set up to give the Pi a static ip on start up. However, when connection is dropped the Pi won't re-establish a connection automatically. I have a script that restarts wlan0. However, the Raspberry Pi has a different ip address than the static ip given to it. This breaks the port forwarding I’ve done to access the Pi from outside the network.
It looks as if my interfaces is not set up quite right. The Pi can be accessed from two ip addresses within the network, one is the static address I defined while the other is not. When wlan0 is restarted, a dynamic ip address is given to the Pi, but not the static address.
Here is my /etc/network/interfaces:
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
iface eth0 inet manual
auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.1.11
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid "ROUTER NAME"
wpa-psk "PASSWORD"
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Here is the script I'm using to reset wlan0:
#!/bin/bash
SERVER=192.168.1.1 #Ping the router
ping -c2 ${SERVER} > /dev/null
#If the exits status from the ping is not 0 (failed)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
fi
Any help is appreciated! Thanks!
Edit:
After looking around with ideas found in this thread, I found /etc/init.d/networking restart does everything I need.So the new script is
#!/bin/bash
SERVER=192.168.1.1
ping -c2 ${SERVER} > /dev/null
if [ $?!=0 ]
then
/etc/init.d/networking restart
echo "Reconnecting!"
fi
I looked around a bit and it seems you may be able to make sure it is set in your wifi script after ifconfig wlan0 up (I've also had to implement such a script on every raspberry pi setup I've ever made due to wifi inconsistencies)
if [$? != 0]
then
#Disable wlan0 and re-enable it
sleep 2
ifconfig wlan0 down
sleep 2
ifconfig wlan0 up
ifconfig wlan0 192.168.1.11
fi
Though it should be noted that I personally have never set up a static ip on a pi, I use a reverse tunneling service so I never have to worry about port forwarding. My answer references this answer from the raspberrypi stackexchange site.
https://raspberrypi.stackexchange.com/questions/9678/static-ip-failing-for-wlan0
Let me know if that helps otherwise I can dig deeper into it.
According to feedback from the asker, the /etc/init.d/networking restart was the answer, read comments below.

Resources