I think its not possible but Is there a way to specify a port for IP addresses listed in the etc/hosts file. If not, how to solve this:

working url: http://raspberrypi.local:1234/mypage

but if I only type this address: http://raspberrypi.local

redirect to http://raspberrypi.local:1234/mypage

How to solve this on raspberry pi? I use the latest debian wheezy img.


You can redirect the standard HTTP port, 80, to one other port using in kernel address translation. If you want to sort it out into different ports, you need an HTTP proxy server.

Create a file like this:

-A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 1234


Call it iptables.rules and su root (you can't use sudo due to redirection):

echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
iptables-restore < iptables.rules

If you get a "command not found", you have to install the iptables package. If you get "iptables: No chain/target/match by that name", then the xt_REDIRECT module is not available to your kernel (but is by default on raspbian, so this should not be a problem).

If you had previous firewall (iptables) rules set up, you obviously want to integrate this into them. The configuration above does not really provide an effective firewall (it just forwards the port from the default used for HTTP, 80), but if you didn't have any rules before, then this won't be any different.

If you are also running a web server on the pi, then this will cut it off -- the traffic will be redirected to mopidy instead. However, you cannot have your cake and eat it too in that case, unless you set up the webserver to redirect certain requests to mopidy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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