Two subnets on one interface

12,371

Try changing /etc/network/interfaces to

auto eth0
iface eth0 inet static
    address 192.168.1.10
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1

auto eth0:1
iface eth0 inet static
    address 192.168.2.10
    netmask 255.255.255.0
    broadcast 192.168.2.255

Restart networking or reboot:

sudo service networking restart 

@2707974 's answer will produce:

SIOCSIFADDR: File exists
SIOCSIFFLAGS: Cannot assign requested address 
SIOCSIFFLAGS: Cannot assign requested address 

Sadly I don't have enough points to comment under his answer.

Updated my answer: @2707974 pointed out that my original answer was bogus -> see question.

Share:
12,371

Related videos on Youtube

user2696964
Author by

user2696964

Updated on September 18, 2022

Comments

  • user2696964
    user2696964 over 1 year

    I'm trying to configure a zoneminder video server that connects to IP cameras on the LAN but I would like the cameras to be on a different subnet to our office and I'm not sure how to accomplish that via static routes.

    It seems that most other about this topic questions are based on having two subnets that each have a router with a gateway. What I'm trying to do is have eth0 connect to 192.168.1.0 and have the cameras be in 192.168.2.0 but be accessible by the server without needing any additional network devices.

    Any ideas?

    • Elliott Frisch
      Elliott Frisch almost 10 years
      You'd have to modify every device on the network, but you could treat "192.168" as a class B network.
  • user2696964
    user2696964 almost 10 years
    should this work with dhcp for eth0 and static for eth0:1? I did this on 14.04 and it was working great and survived several reboots. Than today there was an issue, when I went to /etc/interfaces eth0 was still on dhcp but eth0:1 disappeared. Network manager was apt-get purged btw
  • goozez
    goozez almost 10 years
    I can only guess that the problem is not in the configuration, since it did work for some time. Maybe try this question: IP address alias assigned by DHCP