-1

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
mozcelikors
  • 2,582
  • 8
  • 43
  • 77

2 Answers2

0

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
mozcelikors
  • 2,582
  • 8
  • 43
  • 77
-1

Configure "wlan0" with a static IP

it will work fine

  • 1
    Hello, thanks for your answer, Can you please help me how to edit the file? I added auto wlan0 iface wlan0 inet static address 192.168.1.126 netmask 255.255.255.0 network 192.168.1.1 gateway 192.168.1.1, but it didnt work – mozcelikors Oct 28 '16 at 12:03
  • 1
    https://thepihut.com/blogs/raspberry-pi-tutorials/16683276-how-to-setup-a-static-ip-address-on-your-raspberry-pi – Sukhjinder Singh Oct 28 '16 at 12:07
  • The thing is when I delete "auto eth0", IPv4 address is lost for eth0. I want it to have a IPv4 static address for eth0 i.e. 192.168.20.40, and connect to wlan0 using routers i.e. 192.168.1.1 gateway. Is it possible? When I have "auto eth0" then it doesnt connect to internet. – mozcelikors Oct 28 '16 at 12:18
  • Please follow the steps – Sukhjinder Singh Oct 28 '16 at 12:23
  • Please follow the steps:- 1. ensure that internet is working fine on your router. 2. configure lan card for local networking and check working 3. configure "wlan0" in the last, if it doesn't work then change the configuration according your networking – Sukhjinder Singh Oct 28 '16 at 12:26
  • 1. internet is working fine when ther is no IPv4 address defined for my raspberry pi, also its working now for my other computers. 2. lan card? you mean my ethernet driver on the pc? its also working fine, but it should have nothing to do with the connection on raspberry pi. I think you misunderstood the problem. It is not the same gateway I wanna use for both eth0 and wlan0. It is not a regular static ip connection. I wanna use eth0 for something entirely sepearate (192.168.20.X), and my router gateway is (192.168.1.1). I think problem is being caused by that and I wonder why. Thanks. – mozcelikors Oct 28 '16 at 12:39