Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I keep getting the following error in Chrome:

Error during WebSocket handshake: location mismatch: ws://222.222.222.222/ != ws://222.222.222.222:undefined/

111.111.111.111:80 serves the webpage and there's a websocket connection over 222.222.222.222:80, which redirects to 111.111.111.111:8000

Both 111.111.111.111 and 222.222.222.222 connect to the same physical server.

Here is the HTML code that's generating the error:

<script>
var ws=new WebSocket("ws://222.222.222.222:80");
ws.onmessage=function(evt)
{
   ...
}
etc.
</script>

Originally, it was all working using:

<script>
var ws=new WebSocket("ws://111.111.111.111:8000");
ws.onmessage=function(evt)
{
   ...
}
etc.
</script>

But I can't do this using my 3G modem because port 8000 isn't open. I'm trying to do it all over port 80.

Here is the iptables command I used to send all port 80 connections on 222.222.222.22 to port 8000 on 111.111.111.111

sudo iptables -t nat -A PREROUTING -i eth0 -d 222.222.222.222 -p tcp --dport 80 -j REDIRECT --to-port 8000

Do I also need an OUTPUT iptables option? Not sure what to do...

All this works fine in Firefox Beta 2, but not when I switch to 3G...

share|improve this question
    
This is super hard to understand. Consider rephrasing. It it works fine using a different browser I am not sure how it could be iptables related. However you are saying it with one browser but not with a modem? –  Nathan Powell Aug 6 '10 at 15:38
    
Needs some serious clarification. Is this a problem with the websocket connection, or a question about what port needs to be open on the firewall? Also, consider making 111.way.too.many.characters.repeating into something that doesn't numb my brain, maybe 1.1.1.1? –  Avery Payne Aug 6 '10 at 17:24
    
If you don't understand the setup (it's quite common to have two IP addresses when you need to use a non-standard port to get around corporate proxies), then why bother commenting? Anyway, here's the NAT command I used to achieve what I wanted: sudo iptables -t nat -A PREROUTING -i eth0 -d 222.222.222.222 -p tcp --dport 80 -j REDIRECT --to-port 8000 –  Eamorr Oct 20 '10 at 9:07
    
You're not going to get much help around these parts before you a) start accepting answers to your other questions and b) tone down the attitude a little. –  ThatGraemeGuy Oct 23 '10 at 12:26
    
The only person with "attitude" appears to be you. Plenty of other like-minded helpful people on here (myself included) who are only too willing to share their expertise in a polite and efficient manner. Stupid comments regarding the number of numbers in IP addresses don't help anyone. One wonders why he/she even bothered putting finger to keyboard. Anyway, my problem is solved and hopefully people will learn from this thread (as well as the silly comments). –  Eamorr Oct 23 '10 at 13:30
add comment

1 Answer

Here's the solution to this problem:

Modify /etc/network/interface as follows:

BEGIN    auto eth0    iface eth0 inet static
     address 111.111.111.111
     netmask 255.255.255.0
     gateway 111.111.xxx.xxx
     up ifconfig eth0 add 222.222.222.222   <<<--- This is the line you need to add    
END

Perform: sudo /etc/init.d/networking restart

And do a NAT: sudo iptables -t nat -A PREROUTING -i eth0 -d 222.222.222.222 -p tcp --dport 80 -j REDIRECT --to-port 8000

To stop having to run the NAT command every time the machine reboots, make a startup cron:

Modify crontab (sudo crontab -e) and add the following line:

@reboot root iptables -t nat -A PREROUTING -i eth0 -d 222.222.222.222 -p tcp --dport 443 -j REDIRECT --to-port 8000

share|improve this answer
    
Why the negative sentiment? I suppose all those critics have a better idea up their sleeves? If so, let's hear it. –  Eamorr Oct 23 '10 at 11:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.