ifup eth0 already configured - ethernet

I'm building an operating system for my device with buildroot-2017.08. The operating system that I got started successfully on my device except one big problem:I have no ipv4 address for eth0.
I have an initial script that configures all interfaces that I have. When started it runs the code:
ifup -a.
I've checked that the script really runs at the start of the system and checked the output of ifup. And I get the message:"Interface eth0 already configured". Just after the boot... Who might have configured this interface? I'm stuck. So it doesn't assign the ip address cause it's already configured...
This is my /etc/network/interfaces file
# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
# The loopback interface
auto lo
iface lo inet loopback
# Wired or wireless interfaces
auto eth0
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.0.136
netmask 255.255.255.0
gateway 192.168.0.2
auto can0
iface can0 inet manual
#pre-up ip link set $IFACE type can bitrate 125000 listen-only off
pre-up ip link set $IFACE type can bitrate 125000 triple-sampling on
up ifconfig $IFACE up
down ifconfig $IFACE down
Can somebody give me a clue of what is going on? Maybe I missed some important settings in make-menuconfig or anywhere else. Thank you in advance!

Related

How to emulate QEMU to connect server sockets

I have set up a QEMU virtual machine (VM) trying to emulate an ARM Cortex-A9 cpu on my lubuntu VM (on VirtualBox). Using the kernel, initrd and image of this article, I start QEMU like this:
qemu-system-arm -M vexpress-a9 -cpu cortex-a9
-m 512
-kernel vmlinuz-3.2.0-4-vexpress
-initrd initrd.img-3.2.0-4-vexpress
-drive if=sd,file=debian_wheezy_armhf_standard.qcow2
-append "root=/dev/mmcblk0p2"
-nic user,hostfwd=tcp::5555-:22
After it boots up, I have configurated an static IP on the guest. Modifying the path /etc/network/interfaces.
auto eth0
iface eth0 inet static
address 192.168.0.102
netmask 255.255.255.0
gateway 192.168.0.11
The VM lubuntu, is on the same IP range (192.168.0.1) and my goal is to be able to stablish a connection from QEMU VM to three server sockets which are on port 12000, 13000 and 14000 on the lubuntu VM.
Which parameters do i have to modify/add? I've been reading the network documentation but any test i do, is not working.
UPDATE 1
Following #Peter Maydell advice i changed the network configuration to run a dhcp client instead of an static IP.
# /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
So when running # ip a i get the IP 10.0.2.15/24. Anyways, now I'm being able to reach every net from QEMU but, to be honest, i would prefer to set up a static IP.
You can't just pick an IP address at random for your guest. It has to match the fake network that user-mode networking creates, which is (as the wiki page you link to mentions) on 10.0.2.x by default. It will not (and should not be) on the same IP range as the host or this other VM. The simplest thing is to have the guest run a DHCP client, which will then be able to automatically pick up the right network config from the fake DHCP server that the user-mode networking sets up.
Cross-VM communication as you want should be doable. First check that you can connect from the host to those ports on the lubuntu VM. If you can't do that then you need to fix that VM's config first. Once that is working, then it should also work to connect from the in-QEMU guest to the lubuntu VM on the same IP address/port. This is because outbound connections from the QEMU user-mode-networked guest to either the host or to the outside world require no special configuration. It's only inbound connections to the QEMU guest that need hostfwd setup.

How to get Raspberry Pi‘s wlan1 interface work after poweroff?

I plugged an additional wifi connector in my Raspberry Pi 3B+. I can‘t see the interface of the additional connector after plugging my Raspberry Pi out of power or use sudo poweroff for save shutdown. But after sudo reboot the wifi connector is visible after typing sudo iwconfig in the terminal.
My /etc/network/interfaces contains:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
post-up iw dev $IFACE set power_save off
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
post-up iw dev $IFACE set power_save off
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
My /etc/modules contains:
i2c-dev
bcm2835_wdt
# r8712u # this driver makes problems
r92su
The internal WiFi adapter in my Raspberry Pi 3 b+ is a broadcom and my external WiFi adapter is a Realtek RTL8191SU.
I tried already to shut down the power save mode of the wlan adapter:
post-up iw dev wlan1 set power_save off
EDIT:
Networking.service:
systemctl status networking.service
Returns:
Failed to initialize control interface 'DIR=/var/run/wpa_supplicant GROUP=netdev'. You may have another wpa_supplicant process already running or the file was left by an unclean termination of wpa_supplicant in which case you will need to manually remove this file before.
EDIT 2:
My WLAN connected after
sudo killall wpa_supplicant
sudo poweroff
Shutdown the stream and start Raspberry Pi and it works nice, but if I do this and remove a usb mouse and keyboard it won‘t connect with the wifi. It looks like there is a start problem with usb connectors of the Pi.
EDIT 3:
There seems to be a bug in the system with the USB connection and the current distribution.
Every time I remove the usb mouse and keyboard, the wlan usb adapter is no longer activated.
EDIT 4:
It could also be a driver problem for rtl8191su and therefor r8712u.
My post on the raspberry pi forum:
https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=230193&p=1410456&hilit=wlan1#p1410456
EDIT 5:
I tried already
https://www.raspberrypi.org/forums/viewtopic.php?t=191844
, but after i did this my system won‘t boot correctly and the broadcom internal wlan adapter won‘t work correctly. After this i got wlan0 and wlan1 but both were the same network adapters connected to the same wlan (strange).
So the problem is not fixed until now!
How to get Raspberry Pi‘s wlan1 interface work after shut down the stream and start the Raspberry Pi?
I looked into this issue and here is a fix that I found:
1.In the terminal type sudo nano /etc/network/interfaces
2.Edit your interfaces config file by making sure the text looks like the following...
auto lo
auto wlan0
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp
4.Save your work by pressing Ctrl X and confirming save. Turn the pi off and on
5.When your Pi has restarted bring up the GUI again. Now double click the WiFi Config icon to bring up the wpa_gui properties box. If all was successful you should now see wlan0 show up in the Adapter section. From here you should scan for you SSID and set up the connection.
Hope this helps.
First suppress the loading of the modules by blacklisting and load them in a specific order later on:
Type this to the terminal:
$ sudo vi /etc/modprobe.d/wlan-blacklist.conf
This creates a new file. Make sure to end it with ".conf". Insert your modules here:
blacklist r8712u
blacklist 8192cu
Save and close the file. Now run this:
$ sudo depmod -ae
$ sudo update-initramfs -u
$ sudo vi /etc/modules
At the end of the file you add your modules in the order that they are supposed to show up (i.e. wlan0 before wlan1, etc.):
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
# Parameters can be specified after the module name.
snd-bcm2835
8192cu
r8712u
Then try turning it off and on
I got the solution for this problem:
First load the module (driver) for your usb wlan adapter after the internal chip adapter. In this example case, I got the RTL8191SU with the sudo apt-get install firmware-realtek and therefor r8712u driver.
sudo nano /etc/modprobe.d/wlan-blacklist.conf
Edit wlan-blacklist.conf like this:
blacklist r8712u
After this run:
sudo depmod -ae
sudo update-initramfs -u
sudo nano /etc/modules
Edit modules like this:
i2c-dev
brcmfmac
r8712u
Now load the r8712u module a little bit later after the internal wlan chip of the Raspberry Pi 3b+:
sudo nano /etc/crontab
Add line to crontab:
#reboot root (sleep 20; modprobe r8712u) &
Now have a right interfaces file:
sudo nano /etc/network/interfaces
wlan1 is the realtek wlan adapter and wlan0 the internal broadcom wlan chip:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
post-up iw dev wlan0 set power_save off
auto wlan1
allow-hotplug wlan1
iface wlan1 inet dhcp
post-up iw dev wlan1 set power_save off
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
It is really important, that the default interface is manual!
sudo reboot
or
sudo poweroff
Both of these commands will let the wifi configured correctly. Even if I turn off the raspberry pi and then boot again.
Enjoy your second wlan adapter!

switch raspberry pi from ap to client

I have a raspi with hostapd configured. what i want to do is run a nodejs server so if there is internet via eth0 it makes a hotspot and when there is no internet via eth0 it connects to known wifi networks. my problem is in my interfaces file which looks 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
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
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
when i comment out
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
i can use hostapd to make an AP. but not connect to wifi as a client. if i comment out
iface wlan0 inet static
address 172.24.1.1
netmask 255.255.255.0
network 172.24.1.0
broadcast 172.24.1.255
i can connect to a wifi network but hostapd wont let me make a AP. if i leave both as they are nothing seems to work.
Thank you all in advance.

Double wifi connection (lan / internet) Ubuntu Server

I got Ubuntu Server 16.04.1 with two wireless USB adapters.
I would like to connect to two different wifi:
to my own router with wlan0; to the lan only, just to ssh into the server
to an enterprise network (802.1x/AES/AES) with wlan1 for internet access
I can establish both connections simultaneously but I don't know how to tell wlan0 to connect to the lan only (and not to the internet).
This is my /etc/network/interfaces. With this configuration, both wlan get connected but wlan0 has got internet access and wlan1 shows no internet traffic.
Is there a way to connect wlan0 to my router, with no internet access?
# auto wlan0 → for lan connection only (?)
auto wlan0
iface wlan0 inet static
address 192.168.1.xx
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.254
wireless-essid <my_essid>
wireless-mode managed
wpa-driver wext
wpa-conf /home/<my_username>/<my_essid>.psk.conf
# auto wlan1 → for internet connection
auto wlan1
iface wlan1 inet dhcp
wireless-mode managed
wpa-ssid WOW FI - FASTWEB
wpa-driver wext
wpa-ap-scan 1
wpa-proto RSN
wpa-pairwise CCMP TKIP
wpa-eap PEAP
wpa-key-mgmt WPA-EAP
wpa-identity <my_enterprise_id>
wpa-password <my_enterprise_pw>
wpa-phase2 auth=MSCHAPV2
Found the answer: delete the gateway address so that wlan0 config is
# auto wlan0 → for lan connection only (?)
auto wlan0
iface wlan0 inet static
address 192.168.1.xx
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
wireless-essid <my_essid>
wireless-mode managed
wpa-driver wext
wpa-conf /home/<my_username>/<my_essid>.psk.conf

How does the OS know which network interface to use for the internet?

I have a PC with two network interfaces: eth0 and eth1.
eth0 - Has an ip of 192.168.11.X/24.
eth1 - Has an ip of 192.168.130.X/24. eth1 has internet connectivity.
How does my OS know which interface to use when I try connecting to the internet? Does it iterate over all default gateways? Does it have any cache of what each interface provides? Is there any difference in the behaivior between Windows and Linux?
I'm going to answer for the Linux side of the house (at least for Debian-based systems, such as Ubuntu, since it's more common for users at this point):
Type the following into a command line:
route -n
You should see your "routing table" appear, with something like the following:
Destination Gateway Genmask ... Iface
0.0.0.0 192.168.11.254 0.0.0.0 ... eth0
169.254.0.0 0.0.0.0 255.255.0.0 ... eth0
192.168.11.0 0.0.0.0 255.255.255.0 ... eth0
192.168.130.0 0.0.0.0 255.255.255.0 ... eth1
I omitted a couple columns, but basically, the line that says "0.0.0.0" under "Destination" is the line that determines where your default route is. In other words, where all of the traffic goes that isn't destined for any of the other subnets in the other lines (google.com, facebook.com, whatever).
If it's not right (such as in the above table, where "eth1" is the card you want with Internet access), you should change the default route:
sudo route del default
sudo route add default gw 192.168.130.254 netmask 255.255.255.0
That will fix it for now. To make it permanent, edit your interfaces file:
sudo gedit /etc/network/interfaces
Edit it to look something like the following (change as necessary to your specific situation):
auto eth0
iface eth0 inet dhcp
up route del default
auto eth1
iface eth1 inet dhcp
up route add default gw 192.168.130.254 netmask 255.255.255.0
Then restart networking to see if that did the trick:
sudo /etc/init.d/networking restart
The feature you're asking about is a routing table, a list of destinations known to the host.
When the OS needs to forward a packet it checks this list and chooses the most appropriate one (from specific destinations to general ones). For example:
192.0.2.0/28 - 192.0.2.1 via eth1
198.51.100.0/27 - 198.51.100.1 via eth0
0.0.0.0/0 - 203.0.113.1 via eth0
Note the last destination: it will match any IPv4 address.