Score:0

Dhcp server dont access internet

ru flag

I have 2 ethernet cards in Ubuntu Server 20.04;

enp1s0 my main ethernet card,

enp2s0 my dhcp server ethernet card.

I want devices that receive ip via enp2s0 to access the internet, but if I set the enp1s0 interface to dhcp: false and define a static ip in netplan configuration, enp2s0 can access the internet. But when I do enp1s0 interface to dhcp:true, enp2s0 cannot access the internet. How can I fix this. Thanks for your help.

# /etc/dhcp/dhcpd.conf

default-lease-time 600;
max-lease-time 7200;
authoritative;

subnet 10.0.4.0 netmask 255.255.255.0 {
   authoritative;
   range 10.0.4.1 10.0.0.150;
   default-lease-time 3600;
   max-lease-time 3600;
   option subnet-mask 255.255.255.0;
   option broadcast-address 10.0.0.255;
   option routers 10.0.4.1;
   option domain-name-servers 8.8.8.8;
}

# /etc/netplan/xxx.yaml

network:
  ethernets:
    enp1s0:
      dhcp4: true
    enp2s0:
      addresses:
      - 10.0.4.1/24
      gateway4: 10.0.4.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
  version: 2

# /etc/default/isc-dhcp-server

INTERFACESv4="enp2s0"

# /etc/sysctl.conf

net.ipv4.ip_forward=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.all.forwarding=1

and my iptables rules;

iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m conntrack --ctstate NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -t nat -A POSTROUTING -o enp1s0 -j MASQUERADE
iptables -A FORWARD -i enp2s0 -j ACCEPT
iptables-save | sudo tee /etc/iptables.sav

after iptables rules;

sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
iptables-restore < /etc/iptables.sav

my ip route command output;

default via 10.0.4.1 dev enp2s0 proto static 
default via 10.0.8.1 dev enp1s0 proto dhcp src 10.0.8.36 metric 100 
10.0.4.0/24 dev enp2s0 proto kernel scope link src 10.0.4.1 
10.0.8.0/24 dev enp1s0 proto kernel scope link src 10.0.8.36 
10.0.8.1 dev enp1s0 proto dhcp scope link src 10.0.8.36 metric 100 
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.