0

I am trying to create a dhcp server with iproute2 and the DHCP part is working fine, yet the clients don't get any internet.

The host is getting internet from 192.168.150.0/25 network and functions as a router/DHCP-server for the subnet 192.168.169.0/24.

The clients will get the ip's from the correct ip address range, when I connect them to the same interface as the host machine.

This is my network config.

# Starting interfaces
ip link set dev eth0 up 
ip link set dev eth1 up

# Assigning addresses to interface 
ip addr add "192.168.150.29/25" dev eth0 brd +
ip addr add "192.168.169.1/24" dev eth1 brd +

# Specifying how eth0 will get his internet.
ip route add default dev eth0 via "192.168.150.1" scope global

My question is how can I route the internet connection from eth0 to eth1 as well.

I was trying to add the route like this:

ip route add "192.168.169.1/24" dev eht0

and similar but it says wrong prefix when I have "192.168.169.1" if I change 1 to 0 then I get another error that File exists or Nexthop has invalid gateway.

Thank you in advance

Also as a note: I don't know if it is important, but both eth0 and eth1 is bridged into the machine which is running on libvirt.

2
  • ponder xyproblem.info and please explain in plain words what you are trying to achieve, not how (because it's not working). Giving an example involving "clients", router (and maybe router's router) and Internet would help. Also where is DHCP involved if anywhere?
    – A.B
    May 10 at 19:08
  • Thanks, Now I have made my situation/environment and question more clear. The machine itself is functioning as a DHCP server, for anyone who connects to the interface eth1. Should I include my DHCP configuration files as well?
    – mama
    May 10 at 19:29
1

You need to do ip route add default via 192.168.169.1 dev eht0 on clients or push the route through DHCP server (depends on which one do you use, you don't specify that in your question). Also make sure you have ip_forwarding enabled (/proc/sys/net/ipv4/ip_forward = 1) and make sure you have masquarading (NAT) enabled via iptables/nftables. Alternatively if you control the machine with IP 192.168.150.29, you can add there ip route add 192.168.169.0/24 via 192.168.150.29 and avoid masquarading.

1
  • Thank you. I have access to all the computers, and 192.168.150.29 is the same computer that I am doing the configuration on. When I try ip route add 192.168.169.0/24 via 192.168.150.29 I get error File exists, and if I try ip route it says that the route for 192.168.169.0/24 dev eth1 proto kernel scope link src 192.168.169.1
    – mama
    May 11 at 11:40
0

It turns out that I forgot to disable the default firewall and network manager on my system so I was running SuSeFirewall2 and wicked in the background which was messing up with my settings.

my final network setup ended up like this

#!/bin/bash

case "$1" in
start)
        echo "Starting the network"


        echo "search my.dns.server.ext" > /etc/resolv.conf
        echo "nameserver 192.168.150.1" >> /etc/resolv.conf

        ip addr add "192.168.150.29/25" dev eth0 brd +
        ip addr add "192.168.169.1/24" dev eth1 brd +
        ip link set dev eth0 up
        ip link set dev eth1 up
        ip route add default via 192.168.150.1 scope global

        echo 1 > /proc/sys/net/ipv4/ip_forward

        ;;
stop)
        echo "Stopping the network"
        ip addr flush eth0
        ip addr flush eth1
        ip link set dev eth0 down 
        ip link set dev eth1 down 
        ;;
restart)
        $0 stop
        $0 start
        ;;
*)
        echo "Usage $0 [start|stop|restart]"
esac

I also had to manually setup DNS in /etc/resolv.conf after disabeling wicked, but now it works as a charm.

:-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.