歡迎您光臨本站 註冊首頁

Linux操作系統下單網卡分配多網段的方法

←手機掃碼閱讀     火星人 @ 2014-03-12 , reply:0
   

如果你的DHCP服務只監聽一個網卡,這個網卡綁定多個IP,比如 192.168.0.1,192.168.1.1

  而想要DHCP同時可以分配2個網段的IP請求,像下面這樣的配置(dhcpd.conf)

 
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.100 192.168.0.200 ;
option routers 192.168.0.1 ;
option domain-name-servers 192.168.2.1,202.112.31.58 ;
}
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.100 192.168.2.200 ;
option routers 192.168.1.1 ;
option domain-name-servers 192.168.2.1,202.112.31.58 ;
}

  DHCP 服務是啟動不起來的,會提示 Interface eth0 matches multiple shared networks

  此時只要把上面的配置放到 shared-network中就行了,像下面這樣:
 
shared-network network_tag {
...
}

  一般情況下,單網卡DHCP伺服器分配多網段主要用於VLAN場合,當然DHCP伺服器本生也要能支持VLAN,linux內核已經對802.1q支持了,只需要下載vconfig軟體包進行配置下就行了,具體就不說了,網上很多關於這樣的帖子。下面是一個典型的應用例子:
 
Client Area A -----Switch -----VLAN 1-----------,
Client Area B -----Switch -----VLAN 2-------- Switch ----Trunk --- DHCP Server

Client Area C -----Switch -----VLAN 3-----------'

  DHCP 伺服器在分配IP時,會根據 DHCP 請求數據包中VLAN 的標識來決定分配哪個網段的IP,這樣可以保證同一VLAN的用戶分配的IP始終是同一網段的,當然交換機必須得支持VLAN和DHCP relay功能

  我的配置文件(Ubuntu下)
 
1:/etc/network/interface

auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.254
auto eth0:0
iface eth0:0 inet static
address 192.168.1.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.1.254

2:/etc/dhcpd.conf

default-lease-time 21600;
max-lease-time 21600;
option domain-name-servers 222.92.109.230,61.177.7.1,61.147.37.1;
option domain-name "glfsoft.com";

shared-network network_tag {
subnet 192.168.0.0 netmask 255.255.255.0 {
# range 192.168.0.21 192.168.0.31;
option broadcast-address 192.168.0.255;
option subnet-mask 255.255.255.0;
option routers 192.168.0.254;
next-server 192.168.0.254;
host kook {
hardware ethernet 00:1A:4B:58:36:9D;
fixed-address 192.168.0.9;
}
}
subnet 192.168.1.0 netmask 255.255.255.0 {
# range 192.168.1.21 192.168.1.31;
option broadcast-address 192.168.1.255;
option subnet-mask 255.255.255.0;
option routers 192.168.1.254;
next-server 192.168.1.254;
host kook2 {
hardware ethernet 00:E0:A0:11:BE:21;

fixed-address 192.168.1.9;
}
}
}

 

(責任編輯:A6)



[火星人 ] Linux操作系統下單網卡分配多網段的方法已經有1335次圍觀

http://coctec.com/docs/net/show-post-68292.html