How to redirect a domain name to an IPv4 address in the hosts file with Comcast XFinity IPv6
It’s common practice in web and application development to use a development and/or staging server that is separate from the live production server. This enables development and testing on a separate server that does not interfere with the live production server. Websites and applications generally expect to be accessed through a specific domain name which is used to build full URLs. This presents a potential problem. On one hand you want to access the development or staging server using the domain name. On the other hand you want everyone else to use the same domain name to access the live server simultaneously. This blog post shows how to redirect a domain name using the hosts file on the local development computer. It also covers some potential IPv6 issues with simple workarounds.
How Hosts File Domain Name Redirection Works
When you type a URL with a domain name into your browser’s address bar your computer normally looks up the domain name’s IP addres in a remote DNS server. The IP address is needed to locate that website on the Internet. Before your computer queries the remote DNS sever however, it first looks for that domain name on your local computer. It checks in your computer’s hosts file (/etc/hosts on Mac OS X and Linux/Unix). If it finds an IP address for the domain name in your hosts file then it uses that IP address. In that case it doesn’t need to query the remote DNS server. This is how to redirect a domain name by using the hosts file.
The hosts file can be used to redirect the live server’s domain name to point to the development or staging server rather than the live production server. This only affects your use of the domain name on your computer. It does not affect anyone else’s use of that domain name elsewhere on the Internet. So while everyone else continues using the domain name to access the live production server you may use the same domain name to access the development or staging server from your local development computer.
How to Redirect a Domain Name with a Hosts File
Hosts file domain name redirection is done by simply adding a line to your hosts file. Add the IP address of the development or staging server on a new line followed by a space or tab and then the domain name you wish to point to that IP address. Here’s an example hosts file line using Google.com and one of their IP addresses. I was of course using a different domain name and IP address, but just used Google in the examples for privacy.
Here’s an article about how to edit your hosts file on Windows, Mac or Linux.
Comcast XFinity Problem Redirecting a Domain Name with a Hosts File
Entering the domain name in a browser would then normally redirect the live domain name to the development or staging server. Unfortunately in this case the re-directed domain was still pulling up the live production server instead. I placed a test text file on the development server to test access. The text file came up fine when accessing the development server directly through the IP address but served a 404 not found error when accessing the server through the re-routed domain name which was looking for it on the live production server. Trying with another re-directed domain name produced a 403 Forbidden cloudflare error. So at first I thought it might be a CloudFlare problem.
I initially ruled out potential problems with the server or my local production computer (MacBook Pro running Mac OS X 10.11.06). I was able to access the test text file on the development staging server using the rerouted domain name from the computer when on a Verizon WiFi hot-spot down the street. So it couldn’t be a problem with the development staging server or my local development computer. They both worked fine on the Verizon hotspot.
It was beginning to look more like a problem with the Comcast XFinity network, router or configuration.
IPv6 Addresses Interfering with Redirecting a Domain Name to IPv4 Address in Hosts File
I noticed a clue when performing a Lookup on the redirected domain name in Mac OS X’s Network Utility. In addition to the expected rerouted IPv4 address, it was also returning two IPv6 addresses. Looking those IPv6 addresses up in Google showed that they were pointing to CloudFlare which was where the live production server’s domain normally resolved to. They were the same IPv6 addresses as before I rerouted the IPv4 address. So I started to suspect it was an IPv4 vs. IPv6 DNS routing issue with the Comcast XFinity network, router or configuration.
How to Redirect a Domain Name to IPv4 Address using Comcast XFinity Guest WiFi Hotspot
I contacted Comcast and spoke to people in various departments. I finally reached someone who understood what I was talking about. He didn’t have a final solution for me. Because it worked on a Verizon WiFi hotspot he suggested trying the guest WiFi hot-spot that is bundled with most Comcast XFinity routers. I downloaded the Comcast XFinity WiFi hot-spot configuration installer and logged in to the guest WiFi. The development sever came right up.
So while that didn’t fix the customer gateway it at least gave me a temporary workaround as well as another clue. Now the Network Utility Lookup only showed the re-routed IPv4 address.
How to Redirect a Domain Name to IPv4 Address by Disabling IPv6 with Link-local Only Configuration
The next day I started researching what may be different between the Comcast XFinity normal customer gateway and the bundled guest WiFi gateway. It turns out the guest WiFi gateway doesn’t implement IPv6 but the customer gateway does. So I tried turning IPv6 off. The closest way to accomplish that on Mac OS X is to set Configure IPv6: Link-local only in the Wi-Fi->Advanced->TCP-IP settings.
I was then able to access the remote development server using the redirected domain name. This worked on both Comcast XFinity’s normal customer gateway as well as their bundled guest WiFi. So that is how to redirect a domain name using the hosts file with an IPv4 address. Even if IPv6 addresses are preventing it. Configure IPv6 to Link-local only. As IPv6 becomes more common however I’d expect that ISP networks, routers and configurations would be updated to allow redirection to work without disabling IPv6. But for now this is a quick fix workaround for how to redirect a domain name if you find yourself in similar circumstances.
Your Comcast XFinity Router is an Open WiFi Public Hotspot
Many Comcast XFinity users may not be aware that their home router is being used by Comcast as an open public WiFi hotspot that strangers may use. Anyone in range can simply log into your router’s open public WiFi hotspot (SSID: Xfinitywifi) using their own XFinity username and password for free, or others for a fee. Then they can access the Internet through your router. While this is convenient for XFinity users and others, some may not want strangers using their router.
The public gateway and private gateway are indeed different. As mentioned above, the public gateway doesn’t support IPv6 which was the clue to what was interfering with the hosts file redirection on the private gateway. The two gateways each use different antenna and bandwidth channels. So theoretically it shouldn’t slow down your Internet service. However broadband cable Internet shares the same bandwidth with everyone in the local area. Too many users online in the area will still slow down your connection with shared bandwidth and possible interference.
The other potentially more significant problem is that if those users happen to be doing anything illegal then your router’s IP/MAC address may be dropped in bad places online. The public gateway uses a separate IP address but it still leads to the router in your home. So if you don’t want to risk potentially having your router’s IP/MAC address ending up in places it shouldn’t, you may want to turn off Comcast’s XFinity WiFi Public Hotspot being served from your router.
How to Turn Off the WiFi Public Hotspot on your Comcast XFinity Router
While you can manage most of your WiFi settings through the Comcast router’s web based interface, you can’t directly turn off Comcast XFinity’s WiFi Public Hotspot there. Instead you can log into your online account at XFinity.com and turn it off on their online system rather than on your local router.
- Log into your online XFinity account at XFinity.com
- Go to Services->Internet
- Scroll down to WiFi Public Hotspot
- Click Edit
- Click Turn Off
DreamLight Can Design a Custom WordPress Web Site for You
If you are looking for a WordPress developer DreamLight can develop a custom WordPress website for you. We will work closely with your marketing team to update your existing Web site that may be outdated or to design a brand new custom WordPress Web site. We design all our custom WordPress Web sites to be fully responsive. This means the overall design layout automatically re-flows on-the-fly to take best advantage of all modern mobile devices. We can also create a wide range of integrated branded marketing content for your Web site to help it really stand out, including; 2D/3D digital design, illustration, animation, interactive multimedia or application development.
Contact us for more information about designing a custom WordPress Web site or to explore your specific needs.
Leave a Reply