如何使用一个NIC卡服务不同的子网,根据" dhcp-server-identifier",在centos7

时间:2016-10-08 01:22:25

标签: linux centos7 dhcp

我有一个无法上网的孤立系统。

我想使用其中一个服务器来运行dhcp服务器,并提供不同的ip 客户想要居住的不同子网。

我可以从client到server发送对subnet2的请求,但是服务器总是在subnet1中返回ip。

以下是我的设置。

的/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

&#34;在客户&#34; /etc/dhcp/dhclient.conf

send dhcp-server-identifier 172.16.51.31;

运行dhcp客户端

$ 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.

我向172.16.50.31发送请求。但我只在172.16.50.0/24获得了IP。

我在线阅读了一个解决方案:https://ubuntuforums.org/showthread.php?t=2186879

但这是在Ubuntu,而不是centos。我无法一步一步地做到这一点。

在CentOS 7中是否有任何方法可以在不同子网中提供ip?

0 个答案:

没有答案