0

Please, reopen this question. I really need to understand how to do this - And i saw that a lot of other users have this same problem but no one answered them...

I tried to exemplify with clarity showing even a image of a device that is working like that - Please reopen the question so people can help me?

Thanks!

My network structure has a switch where the gateway is 192.168.1.254, and my computer has the IP address 192.168.17.16

I want to continue using this IP address and use the gateway 192.168.1.254 Why?

To avoid conflicts with another networks - And also, i have a BUNCH of Firewall rules configured for 192.168.17.16.

Is this possible?

I saw a server once that had IP 10.10.1.120 and had a totally different gateway!! It worked just fine but i have no clue on how they did it.

Thanks in advance!

To clarify what i want, here is a example, so it will help you guys understand this question better:

Example

This device achieved what i am trying to do. It has a IP address of 10.99.98.121 and its currently using the same gateway i use on my computer - Which is 192.168.31.254

How?

Raul Chiarella
  • 153
  • 1
  • 10
  • A default gateway is an IP address that traffic gets sent to when it's bound for a destination outside the current network. So by definition, it is totally possible. Now what system is this for which you need configuration? Which device? Which firmware? Which manufacturer? – advay rajhansa Jun 11 '21 at 03:31
  • It's not clear what you mean by "different address". Normally, a gateway has a different address than the device that uses the gateway. Two devices with the same address on the same network will cause trouble. The firewall rules are irrelevant, except if they block access to the gateway. – berndbausch Jun 11 '21 at 06:24
  • The device is a Linux distro: CentOS 7. – Raul Chiarella Jun 11 '21 at 12:13
  • @berndbausch What i mean by different address is exactly that, actually. The gateway is a IP and the IP of the machine is totally different - Gateway: 192.168.1.1 IP Address: 10.10.0.1. I just dont know how to do that. I tried just setting up 192.168.17.16 for the IP and 192.168.1.254 for the gateway but it didnt work... I get host unreacheable – Raul Chiarella Jun 11 '21 at 12:15
  • If i change the IP to 192.168.1.100 (Or another one on the same range than the gateway) and gateway 192.168.1.254 it works :/ I dont want to use 192.168.1.100 tho - I want 192.168.17.16. – Raul Chiarella Jun 11 '21 at 12:16
  • Without change to the router, you'd have to add an address to your system that will be in 192.168.1.0/24 (and you could keep your present address along) to then allow to use the gateway as default route. Beside this not being best practice, adding such address would foil your plan of having "i have a BUNCH of Firewall rules configured for 192.168.17.16" continue to block relevant traffic. – A.B Jun 11 '21 at 13:00
  • Its not a plan. They are already running and working just fine. When i move the server to the switch that has 192.168.17.254 gateway it works just fine... How do i use a gateway that has a different IP address than the IP address of the machine? – Raul Chiarella Jun 11 '21 at 21:45
  • 1
    You ask in a recent comment "How do i use a gateway that has a different IP address than the IP address of the machine?" The gateway *has to be* a different IP address than the IP address of the machine. So maybe you are misunderstanding what a gateway is. This might help: https://serverfault.com/q/262071/450038 – Doug Deden Jun 11 '21 at 22:15
  • 1
    I am still not certain what you mean by "different address". For example, the gateway in my home network is 192.168.1.1, and my PC is 192.168.1.35. Different. I believe you actually mean "gateway's address is not in the same subnet as device's". If so, that would not work. They need to be in the same subnet. The subnet is defined by the CIDR prefix (in my home network: /24) or the netmask (e.g. 255.255.255.0). – berndbausch Jun 12 '21 at 00:00
  • 2
    I don't believe that the example you mentioned (Gateway: 192.168.1.1 IP Address: 10.10.0.1) is legitimate, since these two addresses can't be in the same subnet. – berndbausch Jun 12 '21 at 00:07
  • @berndbausch No, its the address. Not the gateway - The scenario i want: My home network is 192.168.1.1 and my PC is 172.10.10.1... – Raul Chiarella Jun 15 '21 at 14:52
  • @DougDeden Well, im telling you. I was very confused too - But its true. Bro, check it out: https://i.imgur.com/wBBAJtV.png And THIS IP is using the same wireless network than i! It has the same gateway my computer has. – Raul Chiarella Jun 15 '21 at 14:55
  • 1
    The screenshot shows a printer with address 10.99.88.121. I don't see any gateway. If your computer's address is 192.168.17.16, it can use gateway 192.168.1.254 if the prefix is 19 or less. – berndbausch Jun 15 '21 at 15:58
  • The gateway is 192.168.31.254. – Raul Chiarella Jun 16 '21 at 20:12

1 Answers1

0

You can achieve this by defining the default gateway adress and the connection/interface used to reach it. By default your system only knows how to reach the locally defined subnet (I guess it's a /24 network mask, so you can reach adresses 192.168.17.1 to 192.168.17.254 without any changes). Now you must tell it the address of the gateway and which interface is connected to it.

E.g.: You have interface eth0 connected to your LAN with IP 192.168.17.16 and netmask 24 (= 255.255.255.0), then you define the default gateway by saying "default gw is 192.168.1.254 reachable via eth0".

With CentOS7 the network managment is done by NetworkManager. You can use the cli to setup the default gateway:

sudo nmcli connection modify eth0 ipv4.gateway "192.168.1.254"
sudo nmcli connection up eth0

See also https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_static_routes_using_nmcli

You can also modify configuraton files directly by following this guide: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-configuring_static_routes_in_ifcfg_files

Edit (as I can't post comments):

You can connect to any address that is reachable via a physically connected network. The poster didn't tell us if there are multiple physical networks involved and if there is some dedicated router that does the connection between the networks. Therefore I suggest he can reach the gateway directly and only needs to tell his system which interface to use.

puldi
  • 26
  • 1
  • 1
    How can you talk to a device in 192.168.1.0/24 if your interface is in 192.168.17.0/24? How would the router reply to you? It would have no local interface capable of reaching 192.168.17.0/24. – vidarlo Jun 12 '21 at 10:28
  • Well - Thats exactly my question!!!! – Raul Chiarella Jun 14 '21 at 16:54
  • I saw a PRINTER that did that just fine - But automatically... It had a IP 10.10.10.10 and the gateway was my router 192.168.1.1 ._. Well if the printer can do it im certainly that it is possible to achieve this on a Linux server - My question: HOW?? Yo bro you just asked the same question i did. XD Wtf – Raul Chiarella Jun 14 '21 at 16:55
  • I already answered to that question! You don't need to be in the same subnet like the gateway. You only have to be able to reach it via physically attached network(-cable). Defining a subnet to the local host just means that the host implicitly knows how to reach other hosts within this subnet. But you can give it any static route to some other network or single IP address by just telling the host which interface it should use. – puldi Jun 16 '21 at 05:09
  • Well, i marked your question as solved but it was not the answer i was looking for... Since they closed my question there isnt much i can do :| – Raul Chiarella Jun 16 '21 at 20:10
  • You didn't give much additional information on your network topology, therefore it's hard to give the desired answer. On the other hand: Did you try it? Did it work? You can also save a static route on your gateway if the gateway doesn't get the route back to the host automatically. Depends on your gateway. – puldi Jun 17 '21 at 04:47