Configure static IP on eth1

10,960

Solution 1

You have to write before this:

 auto eth1
 iface eth1 inet static
     address 192.168.20.1
     netmask 255.255.255.0
     gateway 192.168.20.1

Solution 2

You forgot to activate your interface:

ifup eth1

Other things regarding your configuration:

  • Add auto eth1 so that you don't have to execute ifup manually
  • As noticed by Zumo de Vidrio, your gateway address is useless, if not wrong. Put in the IP address of the box that connects your Raspberry-Pi to the Internet.
Share:
10,960

Related videos on Youtube

Daniel Gruszczyk
Author by

Daniel Gruszczyk

Currently working in UK as a Software Developer. In my spare time I am rock climbing and MTB racing.

Updated on September 18, 2022

Comments

  • Daniel Gruszczyk
    Daniel Gruszczyk over 1 year

    I want to configure my eth1 interface to have a static IP, even if the cable is not plugged in. Is that at all doable?
    I need that as I want to eventually configure a DHCP server (isc-dhcp-server) to give an IP address to a device that will be connected to my machine via this interface. The device, however might not be plugged in all the time. And it seems like DHCP server will refuse to start if that interface doesn't have an IP/subnet. (please correct me if I am wrong).
    My /etc/network/interfaces has the following entry for eth1:

    iface eth1 inet static
    address 192.168.20.1
    netmask 255.255.255.0
    gateway 192.168.20.1
    

    Still when running ifconfig the eth1 doesn't have an IP assigned.
    I was always completely ignorant in terms of networking etc, so I might be missing something very obvious.
    Any help appreciated. Thanks.

    • schaiba
      schaiba about 7 years
      did you restart the networking service after making the change(s) to /etc/network/interfaces ?
    • Zumo de Vidrio
      Zumo de Vidrio about 7 years
      address and gateway have the same value?
    • Daniel Gruszczyk
      Daniel Gruszczyk about 7 years
      I did restart networking service, and I did down/up of the eth1 interface.
    • Daniel Gruszczyk
      Daniel Gruszczyk about 7 years
      @ZumodeVidrio I took that from here. I am trying to do a very similar thing, except my "host B" would not have a static IP, but rather one assigned by DHCP server.
    • ilkkachu
      ilkkachu about 7 years
      looks like a valid configuration for Debian. Though you didn't say what distribution you have. It doesn't happen to run Network Manager or something similar which would want to control everything? What happens if you remote that odd gateway assignment?
  • Daniel Gruszczyk
    Daniel Gruszczyk about 7 years
    I did restart eth1 (ifconfig eth1 down/up). Also, I don't think that I want to set the gateway as the box that connects me to the internet. Eventually I will aim to redirect all traffic from eth1 to tun0 (OpenVPN connection that I have already running). From examples around internet I saw this done using iptables.
  • xhienne
    xhienne about 7 years
    Your VPN needs a gateway. Maybe it's eth0's gateway? In that case, remove the gateway line for eth1. As for ifup, did you try ifdown --force eth1 before ifup eth1? Also, did you get any error message while ifup'ing ? Does ifconfig show eth1? Else, does ifconfig -a show your IP? Finally, if could help if you show us your whole /etc/network/interfaces config file, can you update your question please?
  • Daniel Gruszczyk
    Daniel Gruszczyk about 7 years
    Thanks! I was missing the auto eth1 line :)