3

I have an isolated system which can not reach the Internet.

I want to use one of the servers to run dhcp server, and give different ip in different subnet that the client want to live in.

I can send request to subnet2 from client to server, but the server always return the ip in subnet1.

Below is my setting.

/etc/dhcp/dhcpd.conf

subnet 172.16.50.0 netmask 255.255.255.0 {
  range 172.16.50.100 172.16.50.200;
  option subnet-mask 255.255.255.0;
  option routers 172.16.50.254;
  option broadcast-address 172.16.50.255;
  option ip-forwarding off;
  option domain-name-servers 8.8.8.8;
  if exists user-class and option user-class = "iPXE" {
    filename "bootstrap.ipxe";
  } else {
    filename "undionly.kpxe";
  }
  next-server   172.16.50.31;
}
subnet 172.16.51.0 netmask 255.255.255.0 {
  range 172.16.51.100 172.16.51.200;
  option subnet-mask 255.255.255.0;
  option routers 172.16.51.254;
  option broadcast-address 172.16.51.255;
  option ip-forwarding off;
  option domain-name-servers 8.8.8.8;
  if exists user-class and option user-class = "iPXE" {
    filename "bootstrap.ipxe";
  } else {
    filename "undionly.kpxe";
  }
  next-server   172.16.51.31;
}

ip setting

$ sudo modprobe dummy
$ sudo ip link set name eth10 dev dummy0
$ sudo ip addr add 172.16.51.31/24 brd + dev eth10 label eth10:0

$ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp1s0f0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 04:7d:7b:d8:bb:6a brd ff:ff:ff:ff:ff:ff
    inet 172.16.50.31/24 brd 172.16.50.255 scope global enp1s0f0
       valid_lft forever preferred_lft forever
    inet6 fe80::67d:7bff:fed8:bb6a/64 scope link
       valid_lft forever preferred_lft forever
3: enp1s0f1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000
    link/ether 04:7d:7b:d8:bb:6b brd ff:ff:ff:ff:ff:ff
4: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 52:54:00:36:03:d7 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
5: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:36:03:d7 brd ff:ff:ff:ff:ff:ff
7: eth10: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN
    link/ether d2:b8:2e:44:a5:2f brd ff:ff:ff:ff:ff:ff
    inet 172.16.51.31/24 brd 172.16.51.255 scope global eth10:0
       valid_lft forever preferred_lft forever

$ifconfig

enp1s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.16.50.31  netmask 255.255.255.0  broadcast 172.16.50.255
        inet6 fe80::67d:7bff:fed8:bb6a  prefixlen 64  scopeid 0x20<link>
        ether 04:7d:7b:d8:bb:6a  txqueuelen 1000  (Ethernet)
        RX packets 5288228  bytes 1902558434 (1.7 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6310647  bytes 6023578728 (5.6 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdfe20000-dfe3ffff

enp1s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 04:7d:7b:d8:bb:6b  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device memory 0xdfe00000-dfe1ffff

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 6164718  bytes 2009821769 (1.8 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6164718  bytes 2009821769 (1.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:36:03:d7  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

"in client" /etc/dhcp/dhclient.conf

send dhcp-server-identifier 172.16.51.31;

run dhcp client

$ dhclient -r -v ens20f0
    Listening on LPF/ens20f0/54:ab:3a:3d:2c:7a
    Sending on   LPF/ens20f0/54:ab:3a:3d:2c:7a
    Sending on   Socket/fallback
    DHCPRELEASE on ens20f0 to 172.16.50.31 port 67 (xid=0x41973da)

$ dhclient -s 172.16.51.31 -v ens20f0
    Listening on LPF/ens20f0/54:ab:3a:3d:2c:7a
    Sending on   LPF/ens20f0/54:ab:3a:3d:2c:7a
    Sending on   Socket/fallback
    DHCPDISCOVER on ens20f0 to 172.16.51.31 port 67 interval 7 (xid=0x2c4dfe6c)
    DHCPREQUEST on ens20f0 to 172.16.51.31 port 67 (xid=0x2c4dfe6c)
    DHCPOFFER from 172.16.50.31
    DHCPPACK from 172.16.50.31 (xid=0x2c4dfe6c)
    bound to 172.16.50.116 -- renewal in 20324 seconds.

I send a request to 172.16.50.31. But I only got the ip in 172.16.50.0/24.

I have read one of solution online: https://ubuntuforums.org/showthread.php?t=2186879

But that is in Ubuntu, not centos. I can't do it step by step.

Is there any method to give ip in differnet subnet in CentOS 7?

1

I found the solution by myself.

Adding the virtual interface as permanent interface in /etc/sysconfig/network-script/ will let the server offer multi subnet with one real interface.

If the interface is added as temporary one .(ex. ifconfig eth0:1 172.16.52.0/24 ), the server will not be able to serve with multi subnet.

| improve this answer | |

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.