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

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.

Related

check whether eth0 is up while my active connection is ppp0

I've my eth0connection and I've a ppp0 connection.
keeping alive my ppp0 connection, can I test eth0 connection?
like checking
ping <ip> <eth0 connection>
Have you tried the following (Copying from different question that uses your issue unix.stackexchange)?:
If you look at ping manual man ping, you can read:
-I interface address
Set source address to specified interface address. Argument may be numeric IP
address or name of device.
So try, e.g.:
ping -I eth0 google.com

Pass IP-address to cloud-init metadata

I am searching for a way to pass a ip-address to cloud-init metadata. So when my qcow boots, it does not have to wait for 120 - 180 seconds to boot.
Currently I've created a workaround by adding IP-address information to the userdata part of cloud-init. The con is, it does take some time because cloud-init userdata is only executed after booting the VM.
echo -e "
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
\taddress $address
\tnetmask $netmask
\tgateway $gateway
\tdns-nameservers $dnsnameservers
" > /etc/network/interfaces
ifdown eth0; ifup eth0
Currently to set the hostname in cloud-init metadata, I've already obtained this part:
cat > $config_dir/meta-data <<-EOF
instance-id: $uuid
hostname: $hostname
local-hostname: $hostname
EOF
But I need something more solid, more concrete because the cloud-init documentation is very vague
EDIT: I've seen that it is possible because Openstack can do it.
It is possible by using the following format:
network-interfaces: |
auto lo
iface lo inet loopback
iface eth0 inet static
address xxx.xxx.xxx.xxx (static ip)
netmask xxx.xxx.xxx.xxx
gateway xxx.xxx.xxx.xxx (gateway ip, usually ip address of router)
You basically write out the configuration you want your interfaces to have as an interfaces file would look as long as you have 'network-interfaces: |'
Hope that answers your question!

Assigning static ip in linux [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've tried to assign static ip to my raspberry computer, yet it doesn't assign it after rebooting. My /etc/networ/interfaces file looks like this:
auto lo
iface lo inet loopback
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
gateway 192.168.1.1
#iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
After rebooting and using ifconfig command it shows me that the address is different. What should I do to make it assign data from the file?
It's /etc/network/interfaces not /etc/networ/interfaces and you forgot to add:
auto eth0
iface eth0 inet static
You should do:
/etc/init.d/networking restart
or
ifdown eth0
ifup eth0
Instead of rebooting, Also make sure that 192.168.1.2 isn't used already.
Try changing
auto lo
to
auto lo eth0
As this will make ifup -a run during system startup configure eth0 as well. (see man interfaces).

Dynamic Switching of WiFi using a shell program in Raspberry Pi / Ubuntu / Debian

How can I check in a shell script, whether the system is connected to WiFi-1 and if not connected, connect to WiFi-2? I tried using wpa_supplicant and interfaces configurations, but not working as expected. I followed this tutorial
If there is any other way of doing this, please let me know.
/etc/network/interfaces file
auto eth0
iface eth0 inet6 manual
pre-up ip link set dev eth0 up || true
wpa-iface eth0
wpa-driver wired
wpa-conf /etc/wpa_supplicant/wpa_supplicant_wired.conf
pre-down /etc/netplug/netplug eth0 out >/dev/null 2>&1 || true
post-down ip link set dev eth0 down || true
auto wlan0
iface wlan0 inet manual
pre-up ip link set dev wlan0 up || true
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wpa-driver wext
pre-down /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
post-down ip link set dev wlan0 down || true
# open is specific (IPv6 only) so I just stop dhcp via netplug
iface open inet manual
up /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
iface default inet manual
up /etc/netplug/netplug wlan0 in >/dev/null 2>&1 || true
down /etc/netplug/netplug wlan0 out >/dev/null 2>&1 || true
I think you may have already found the solution by now. Anyway as a workaround to do this you can install Network manager (supports all debian distributions including ubuntu/raspbian/etc)
sudo apt-get install network-manager
And then add required network configuration to /etc/NetworkManager/system-connections folder.
Sample configuration for a wifi network connection as follows:
[connection]
id=milanWiFi
uuid=56439211-1067-4334-b199-b73ceed32d83
type=802-11-wireless
[802-11-wireless]
ssid=milanWiFi
mode=infrastructure
mac-address=84:3A:4B:9B:CF:66
security=802-11-wireless-security
[802-11-wireless-security]
key-mgmt=wpa-psk
auth-alg=open
psk=milan123
[ipv4]
method=auto
[ipv6]
method=auto
Here, id is an unique name for your connection and you can obtain uuid by calling,
uuidgen command in the console.
For you to get the available wifi connections, you can use
sudo iw dev wlan0 scan
and there you can see the relevant details about the connections. What you have to do is to grab the details out of it and create the configuration file.

How to set up autoip with local-link (RNDIS) on linux and embedded 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

Resources