static IP setting

I've been running my Pi on a WiFi dongle for quite some time with a static IP address set in /etc/hosts, and it seems happy, but in due course, I want to move it over to a wired connection, with a static IP address.

After a bit of googling, I found out that I need to edit my /etc/network/interfaces file, which I've now done :

auto lo

iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.105 netmask 255.255.255.0 gateway 192.168.1.254 network 192.168.1.0 broadcast 192.168.1.255

allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp

And that works fine on a wired connection.

However, when I unplug the network cable and plug the dongle back in (and reboot), it doesn't want to play (I can't ping it, and it can't ping outwards). A bit more reading suggested a further edit to the file to give :

auto lo

iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.105 netmask 255.255.255.0 gateway 192.168.1.254 network 192.168.1.0 broadcast 192.168.1.255

allow-hotplug wlan0 iface wlan0 inet static address 192.168.1.105 netmask 255.255.255.0 gateway 192.168.1.254 network 192.168.1.0 broadcast 192.168.1.255

wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp

But It still doesn't work.

If the dongle is plugged in with the upper interfaces file in use, it flashes, but running ifconfig gives :

eth0 Link encap:Ethernet HWaddr b8:27:eb:49:2a:e5 inet addr:192.168.1.105 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:54 errors:0 dropped:1 overruns:0 frame:0 TX packets:126 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:4661 (4.5 KiB) TX bytes:8792 (8.5 KiB)

lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:36 errors:0 dropped:0 overruns:0 frame:0 TX packets:36 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:3168 (3.0 KiB) TX bytes:3168 (3.0 KiB)

wlan0 Link encap:Ethernet HWaddr 80:1f:02:82:aa:e0 inet addr:192.168.1.114 Bcast:192.168.1.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:122 errors:0 dropped:127 overruns:0 frame:0 TX packets:6 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:17909 (17.4 KiB) TX bytes:1176 (1.1 KiB)

Whereas when the lower one is in use, it doesn't flash. and ifconfig shows no errors.

So, how do I get it to work with the dongle again. With the Pi in its current location, WiFi is the preferred option (if only to reduce the amount of wiring running around the room).

Going back to the original interfaces file doesn't seem to be an option as I can't get it to work with that either.

TIA

Adrian

--
To Reply : 
replace "bulleid" with "adrian" - all mail to bulleid is rejected 
Sorry for the rigmarole, If I want spam, I'll go to the shops 
Every time someone says "I don't believe in trolls", another one dies.
Reply to
Adrian
Loading thread data ...

Adrian Inscribed thus:

Try giving one or the other interfaces its own address or use DHCP.

--
Best Regards: 
                        Baron.
Reply to
Baron

Not static on eth0 but with dhcp on both here is my working interfaces:

auto lo iface lo inet loopback auto eth0 allow-hotplug eth0 iface eth0 inet dhcp auto wlan0 allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf wpa-ssid ********* wpa-psk *********** wpa-key-mgmt WPA-PSK wpa-group TKIP CCMP iface default inet dhcp

--
Regards 
Dave Saville
Reply to
Dave Saville

That appears to be consistent with what you asked for in /etc/network/interfaces: a dhcp addres for wlan0, a static address for eth0. What's the problem? Just connect to the dhcp address, which presumably you've configured your router to install in local DNS.

It's a bad idea to try to have the same address on both interfaces at once. If you want two separate static addresses, make them different ones. Otherwise you're relying on the switch fabric to do the right thing.

R
Reply to
Roger Bell_West

In message , Roger Bell_West writes

Thanks for the detailed reply.

What I want is to be able to use a static IP address whether I'm using WAN or ETH. Apart from when I was playing around this afternoon, I wouldn't have the dongle and a cable plugged in at the same time. To me, it makes sense to use the same IP address for both interfaces (as only one would be active at any time).

When I get a chance, I'll try setting the interfaces file with different IP addresses for the two interfaces.

Adrian

--
To Reply : 
replace "bulleid" with "adrian" - all mail to bulleid is rejected 
Sorry for the rigmarole, If I want spam, I'll go to the shops 
Every time someone says "I don't believe in trolls", another one dies.
Reply to
Adrian

Then is is best to use DHCP and configure your DHCP server so that it serves the same static IP address for both MAC addresses (of the eth0 and the wlan) involved.

This configuration allows the Pi to set the address to only one interface at a time, and still you have automatic switching. I use it here, and it works fine.

Reply to
Rob

Agreed.

The difficulty with using the same static address on two interfaces at once is that the ethernet transceiver can't reliably detect whether it has a cable plugged in or any ability to route packets. (Yes, I know about the link light. There are some interesting edge cases.) So in your configuration, both interfaces show as "up"; each packet might go out through either, because they both look equally valid.

You could I suppose have an init script that tries to bring up wlan0 and then falls back to eth0 if that fails, but the DHCP option will probably be less trouble.

Reply to
Roger Bell_West

Not on my Pis, but on a Debian Linux PC, which has an almost identical setup, I use the pre-up option in e/n/i to check if an interface has a link before trying to bring it up.

If the pre-up command returns False, then the interface isn't started, so my interfaces file is something like:

iface eth0 inet static pre-up /usr/local/eth0-check address blah-blah etc...

iface wlan0 inet static pre-up /usr/local/wlan0-check address blah-blah etc

eth0-check would use something like ethtool to check for a link and return true if one exists.

wlan0-check would check to see if eth0 is up and return false if it is.

(I actually do use DHCP, but this would work with static addresses too).

It won't switch from on to the other if one interface loses connection while up though.

Reply to
Dom

Thanks for the suggestions.

I think I've now got the router set up to do this. A quick reset of the interfaces file and a reboot, and I'm back working on WiFi.

Adrian

--
To Reply : 
replace "bulleid" with "adrian" - all mail to bulleid is rejected 
Sorry for the rigmarole, If I want spam, I'll go to the shops 
Every time someone says "I don't believe in trolls", another one dies.
Reply to
Adrian

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.