In a virtual network, I have two hosts,let's call : A and B with ip addresses of 10.0.0.1 and 10.0.0.4. Beetween the hosts there is a router with two different network cards,and two different ip addresses.I've set the gateway, and the hosts can now ping with the router and vice versa.Still, A can't reach B towards the router.I've already enabled the ip forwarding in sysctl. Am I missing something here?
closed as too broad by Ron Maupin♦ Jul 7 '18 at 20:37
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
You need to make sure the two hosts are in different IP networks. If the hosts are in the same network then they will attempt to ARP directly for the other host and not use the gateway. In this case as they are not in the same LAN, pings will fail.
Most routers won’t let you configure the same network on two different interfaces, but I know that some do. If this is the case, they expect the two interfaces to be connected to the same LAN, which it doesn’t sound like yours is.
So you can either connect both hosts to the same LAN, they won’t need the gateway to speak to each other in this case. Alternatively put both hosts on different IP networks and use the router as default gateway for both networks.
If you are using /24 subnet masks (255.255.255.0) try:
Interface 1 Router address: 10.0.0.1/24 Host address: 10.0.0.2/24
Interface 2 Router address 10.0.1.1/24 Host address 10.0.1.2/24
Make sure you configure the correct default gateways on the hosts and as long as routing is enabled on the router it will probably work.
A and B with ip addresses of 10.0.0.1 and 10.0.0.4
First of all: For routing, is not posible that you have those IPs in differents networks connected across router, because:
- If you use netmask 24, there are on the same subnet,
- If you use netmask 30, the firts is correct, 10.0.0.0/30 with network 10.0.0.0/30, 10.0.0.1 and 10.0.0.2 for hosts and 10.0.0.3 for broadcast; but for the second one, network address would be 10.0.0.4/30, 10.0.0.5 and 10.0.0.6 for hosts and 10.0.0.7 for broadcast, like you see, your are using 10.0.0.4 as host address.
So, with this, your scenario will be something like this: