Wednesday, April 24, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 6982  / 2 Years ago, wed, july 20, 2022, 3:12:55

I'm relatively inexperienced with networking, but I know what I want to achieve in this case. I have a computer that I physically move between two separate local networks, but when the computer is on one of those networks I want to assign a different static IP address to the machine.



One internal network is 192.168.1.0, and the other is 192.168.2.0. Therefore, I want one static IP address to be 192.168.1.x and the other to be 192.168.2.x.



Is there a way of assigning two static IPs, but with only one taking effect depending on the network its connected to? Can this be done purely in /etc/network/interfaces, for example?



I may well have misunderstood the situation, so if there's a different way of achieving what I want then I'm happy to hear the solution.


More From » networking

 Answers
4

There may be better solutions (at least ones closer to what you're asking for) but here's what springs to my mind:




  • Configure the DHCP servers at each location to assign your MAC address a static IP, and on the laptop, just have it automatically grab the IP from DHCP. This is by far the easiest if you have router access at each place.


  • The next three are essentially the same solution as each other - split the connections up:




    • Add and use a different network card for one location.

    • Leave USB network cards on the two ethernet cables (slower than native gigabit).

    • Use two wireless connections. Network Manager can do the hard stuff automatically so you just roam from one place to another.


  • Script something for when the interface comes up. I don't know what the event would really be called - but you essentially want to know when the cable is plugged in and the whole thing is ready to go. You could just have a static setup for one network and wait for when that comes up.




    • Bind in using upstart if you know the connection is there on boot, or consider this Call script after connecting to a wireless network if you make the connection after boot.


    • When the network is up, do some service discovery. Is the gateway where you expect it? Are there other known servers you should be able to ping?


    • If everything is correct, leave the configuration as it is, otherwise switch to the alternative network configuration. You can either manually set this up using ifconfig or you can have two connections set up in Network Manager and just use nmcli to switch which one you're on.





Out of the three, DHCP is the easiest.


[#36131] Thursday, July 21, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rtbrbab

Total Points: 461
Total Questions: 126
Total Answers: 117

Location: Saudi Arabia
Member since Fri, Jul 1, 2022
2 Years ago
rtbrbab questions
Fri, May 5, 23, 14:22, 1 Year ago
Tue, Nov 16, 21, 14:41, 2 Years ago
Thu, Mar 23, 23, 20:47, 1 Year ago
Sat, Jun 18, 22, 21:36, 2 Years ago
;