Search code examples
linuxnetwork-programminginterfaceraspberry-pistatic-ip-address

Network configuration for static IP and automatic wifi connection


I would like to set up my Raspberry Pi as static IP device, which communicates over Ethernet (through an IP like 192.168.20.X), and at the same time it should be connected to the internet through WLAN (192.168.1.1). However when I allow 'auto eth0' then it does not configure the wlan0. I would like both of them to work. My current configuration is given below:

source-directory /etc/network/interfaces.d
auto lo

iface lo inet loopback

auto eth0  
iface eth0 inet static
 address 192.168.20.40
 netmask 255.255.255.0
 network 192.168.20.1
 gateway 192.168.20.1


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

What am I missing? Any help would be appreciated. Thanks in advance.

SOLVED:

source-directory /etc/network/interfaces.d
auto lo

iface lo inet loopback

auto eth0  
iface eth0 inet static
 address 192.168.20.45
 netmask 255.255.255.0
 network 192.168.20.1
 gateway 192.168.1.1    # Changing this worked
 dns-nameservers 8.8.8.8 8.8.4.4

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

Solution

  • SOLVED:

    source-directory /etc/network/interfaces.d
    auto lo
    
    iface lo inet loopback
    
    auto eth0  
    iface eth0 inet static
     address 192.168.20.45
     netmask 255.255.255.0
     network 192.168.20.1
     gateway 192.168.1.1    # Changing this worked
     dns-nameservers 8.8.8.8 8.8.4.4
    
    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