7

Trying to set two static ip in dhcpcd.conf, but second ip is not active.

dhcpcd.conf

interface eth0
    static ip_address=192.168.3.99/24
    static routers=192.168.3.61
    static domain_name_server=192.168.3.61

interface eth0:1
    static ip_address=192.168.4.55/24
    static routers=192.168.4.50
    static domain_name_server=192.168.4.50

ifconfig output:

inet addr:192.168.3.99  Bcast:192.168.3.255  Mask:255.255.255.0

Does anyone faced similar situation.

5

Although it is said that /etc/network/interfaces is deprecated (read it everywhere online) so far the only way I have been able to make it work is in fact through /etc/network/interfaces. The 'modern' way described in official Debian documentation in fact states that this new method is dangerous.

The following should work for you, just put it in /etc/network/interfaces (you can leave out the gateway)

auto eth0:1
allow-hotplug eth0:1
iface eth0:1 inet static
    address 192.168.4.55
    netmask 255.255.255.0
    gateway 192.168.4.50

if you just want it to be temporary (not lasting after reboot) you could also use

sudo ifconfig eth0:1 192.168.4.55/24 
  • 3
    Instead of modifying /etc/network/interfaces, I leave the file /etc/network/interfaces untouched to keep dhcpcd working as intended, while adding a file such as /etc/network/interfaces.d/eth0-mydb to have the additional IP address configured. – VCD Jun 27 '18 at 14:09
2

I suggest you use ip address show instead of ifconfig to see your ips, anyway with new debian/raspbian Jessie's versions, you may solve using multiple static configuration in this way:

interface eth0
arping 192.168.2.1
arping 192.168.4.50

profile 192.168.2.1
static ip_address=192.168.2.44/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

profile 192.168.4.50
static ip_address=192.168.0.44/24
static routers=192.168.4.50
static domain_name_servers=192.168.4.50

source and more: Static IP address templates for dhcpcd.conf

  • I could not get this approach to work, while adding a clause to /etc/network/interfaces.d/eth0-xxx (as per @F. Pareto and answer) worked fine. – askvictor Jan 16 at 0:22
  • ok but you have to change that manually if you change network.. On the other hand, in my way, you need to know the addresses of the servers becouse If none of the arpings find an active machine then you will get a DHCP allocation – lunix15 Jan 17 at 16:43
  • arping is for selecting one out of several possible static configurations, not for setting multiple IP addresses on one interface – Adrian W Feb 16 at 16:08
0

yes, and a long time ago. Try /etc/network/interfaces : it's a proper place to make a config. DHCP client can assign only one IP, as DHCP protocol itself. Even more : DHCP is for getting a config from server. If you have a local per-host config, then use a proper place for it in your system

0

Except the latest version of Jessie overwrites /etc/network/interfaces so it may HAVE been the proper place before - but alas no longer

0

I got my raspberry pi(jessie) to run two IPs on the same interface and on the same vlan by appending "denyinterfaces eth0" to dhcpcd.conf, and running an @reboot crontab job using "ip" commands.

$ sudo nano /etc/dhcpcd.conf  
-------------------------
denyinterfaces eth0


$ sudo nano /etc/ipstartup
-----------------------
ip address flush dev eth0
ip address add 10.0.0.2/24 dev eth0
ip address add 10.0.0.3/24 dev eth0
ip link set eth0 up
ip route add default via 10.0.0.1
printf "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf


$ sudo chmod 740 /etc/ipstartup


$ sudo crontab -e
-----------------
@reboot /etc/ipstartup

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.