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.

My customers are running many scripts that uses memcached, but all of them are using localhost as a address. My localhost server is now out of RAM, because it's doing many other things like WWW and MySQL servers.

Now I got a brand new server with 16 GB RAM which I can use as a dedicated memcached server. How to redirect localhost:12111 to domain.com:12111 server ?

I can't switch localhost to something else in /etc/hosts because all my databases use such address.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Make an effort, 1 minute of Googling would give you the answer.

In no particular order, you could use:

  1. Xinetd
  2. Rinetd
  3. IPTables
  4. SSH tunnel
  5. Netcat
  6. Layer 4-7 balancing (eg haproxy)

Or do a simple grep for localhost and replace it with a hostname that you can change.

iptables

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -j MASQUERADE
iptables -t nat -A PREROUTING -d 127.0.0.1 -p tcp --dport 11211 -j DNAT --to 192.168.1.2:11211
iptables -P FORWARD ACCEPT

rinetd

echo " 127.0.0.1 11211 192.168.1.2 11211" >> /etc/rinetd.conf
/etc/init.d/rinetd restart

netcat

nc -l -p 11211 -c "nc 192.168.1.2 11211"

ssh

ssh user@192.168.1.2 -L 11211:192.168.1.2:11211

xinetd

cat > /etc/xinet.d/memfw << eof
  service memfw {
    disable = no 
    type = UNLISTED 
    socket_type = stream 
    protocol = tcp 
    user = nobody 
    wait = no 
    redirect = 192.168.1.2 11211
    port = 11211
  }
eof
share|improve this answer
    
I think first and the last are far the best. –  Andrew Smith Jun 24 '12 at 23:01
    
Thank you ! It works ;) –  Spacedust Jun 25 '12 at 14:09

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.