16

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.

Avin Varghese
  • 261
  • 1
  • 2
  • 6

4 Answers4

7

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 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 
goldilocks
  • 60,325
  • 17
  • 117
  • 234
F. Pareto
  • 191
  • 1
  • 5
4

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

lunix15
  • 41
  • 3
1

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
Jaredk
  • 11
  • 2
-1

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

Alexey Vesnin
  • 926
  • 10
  • 17