You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Ubuntu上配置bind9 DNS服务器,解析CentOS虚拟机主机名

Got it, let's walk through how to get this set up step by step so your clients can access the CentOS web server via http://ixchariot-server/. Here's what we need to tackle:

1. Set the Hostname on Your CentOS Virtual Machine

First, log into your CentOS VM and set its hostname permanently:

sudo hostnamectl set-hostname ixchariot-server

Verify the change with hostname—it should output ixchariot-server.

Next, update the /etc/hosts file to map the VM's IP to its new hostname (this helps local resolution on the VM itself):

sudo nano /etc/hosts

Add this line at the bottom:

172.29.15.7 ixchariot-server ixchariot-server.localdomain

Save and exit (Ctrl+O, Enter, Ctrl+X). You can log out and back in to see the hostname update in your shell prompt.

2. Configure Domain Resolution on the Ubuntu Host

Since your Ubuntu machine acts as both a DHCP server and a DNS resolver for clients, we need to make sure it can map ixchariot-server to the CentOS VM's IP, and that it shares this mapping with clients.

2.1 Update Ubuntu's Local Hosts File

First, add the mapping to Ubuntu's /etc/hosts so the host itself can resolve the name:

sudo nano /etc/hosts

Add this line:

172.29.15.7 ixchariot-server

Save and exit. Test it with ping ixchariot-server—you should see responses from 172.29.15.7.

2.2 Configure DHCP to Serve the Correct DNS & Domain Mapping

Assuming you're using dnsmasq (a common combined DHCP/DNS tool on Ubuntu) for your DHCP server:

  1. Open the dnsmasq config file:
    sudo nano /etc/dnsmasq.conf
    
  2. Add this line to force all clients using your DHCP to resolve ixchariot-server to the VM's IP:
    address=/ixchariot-server/172.29.15.7
    
  3. Also make sure your DHCP config tells clients to use the Ubuntu host as their DNS server. Look for a line like:
    dhcp-option=option:dns-server,172.29.15.1
    
    If it's not there, add it.
  4. Restart dnsmasq to apply changes:
    sudo systemctl restart dnsmasq
    

If you're using isc-dhcp-server instead:

  • Update your DHCP config (usually /etc/dhcp/dhcpd.conf) to set the DNS server to 172.29.15.1:
    option domain-name-servers 172.29.15.1;
    
  • Then, on Ubuntu, set up a local DNS server (like dnsmasq or bind9) that includes the ixchariot-server -> 172.29.15.7 mapping.
3. Ensure Network Routing Between Client Subnet and VM Subnet

Since your clients are on the 172.29.14.x subnet and the CentOS VM is on 172.29.15.x, you need to enable IP forwarding on the Ubuntu host to let traffic pass between the two:

  1. Enable forwarding temporarily:
    sudo echo 1 > /proc/sys/net/ipv4/ip_forward
    
  2. Make it permanent by editing /etc/sysctl.conf:
    sudo nano /etc/sysctl.conf
    
    Find the line net.ipv4.ip_forward=0 and change it to:
    net.ipv4.ip_forward=1
    
  3. Apply the change:
    sudo sysctl -p
    
4. Test the Setup
  1. On a client machine (e.g., 172.29.14.1), verify it's using 172.29.15.1 as its DNS server (check with nslookup or ipconfig/ifconfig).
  2. Ping ixchariot-server from the client—you should get responses from 172.29.15.7.
  3. Finally, open a browser and navigate to http://ixchariot-server/—you should see your CentOS web server's content.

内容的提问来源于stack exchange,提问作者SamJ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:29:32