Run SSH SOCKS server as a daemon in CentOS

This post relies on the previous tutorial on how to quickly setup a SOCKS server.

Again, this is all one in the client side.

First you need to make sure you can autologin to the server acting as the SOCKS server. This is achieved by setting. Make sure you have your own public see so the server can know who you are.

[root@Client ~]# ls .ssh/|grep id
id_rsa
id_rsa.pub

If you don’t have any of these files just create the using the following command. Just press enter on every promtp.

[root@Client ~]# ssh-keygen -t rsa

Then add the autologin to your remote server using this command by changing the server ip to adjust to your scenario.

[root@Client ~]# cat ~/.ssh/id_rsa.pub | ssh user@yourserver ‘cat >> .ssh/authorized_keys’

Now test it by logging in. It should not prompt for any password and go straight to your server console.

[root@Client ~]# ssh user@yourserver
[user@yourserver ~]#

Now that you have the autologin setup, you can set your SOCKS server access by creating an upstart job.
Create a file under /etc/init/socks.conf and paste the following source. Remember to change your user and yourserver ip address to match your current scenario. In this case I’ll setup the SOCKS server in port 443.


# socks - SOCKS server access daemon
#
# This service setups a SOCKS server connection to a specified server
#

start on runlevel [0123456]

stop on runlevel [!$RUNLEVEL]

respwan
respawn limit 15 5
expect fork
exec ssh -v -N -f -D 443 user@yourserver >/tmp/log.log 2>&1

Then just run the upstart command to start your service.

[user@Client ~]# start socks

To make sure the proxy service is running you can use netstat.

[user@Client ~]# start socks
socks start/running, process 1151
[root@socksserver ~]# netstat -tlnp|grep 1151
tcp 0 0 127.0.0.1:443 0.0.0.0:* LISTEN 1151/ssh
tcp 0 0 ::1:443 :::* LISTEN 1151/ssh

And that is all. Whenever your server reboots the service will start automaticly. If the SSH daemon goes down, upstart will restart it,

Setup a DNS proxy in CentOS

Today we are going to learn how to install a DNS server and client using CentOS. The DNS server is perhaps the most important part of the deal. However, there are plenty of support client OSs which can be either Windows, Linux, or Mac.

Server:

So first we go to the server and install iodine. Make sure you don’t have any other process that is using 53. If you do just change it so something else and use -b option in iodined server to relay any

yum search iodine
yum install iodine.x86_64

Then run the command

# iodined -P mypass 172.16.0.1 ns1.yourserver.com
Opened dns0
Setting IP of dns0 to 172.16.0.1
Setting MTU of dns0 to 1130
Opened UDP socket
Listening to dns for domain ns1.yourserver.com
Detaching from terminal…

To make iodined a service just write this to /etc/init/iodined.conf

start on runlevel [2345]
stop on runlevel [S016]

respawn
respawn limit 150 25
expect daemon
exec iodined -P mypass 172.16.0.1 ns1.yourserver.net 2>&1 >/tmp/iodine_boot.log

Client

Run the same command to install iodine. I’ll assume CentOS is the clients platform

yum install iodine.x86_64

Then start iodine

iodine -r -f -P mypass ns1.yourserver.com

To automaticly start it in the client side use this upstart job in file /etc/init/iodine.conf

start on runlevel [2345]
stop on runlevel [S016]
respawn
respawn limit 150 25
exec iodine -r -f -P mypass 1.2.3.4 ns1.yourserver.net >/tmp/iodine_boot.lo

And that’s it. To run the client side just type start iodine. After you run your client you just need to ping 172.16.0.1, which is the server ip address.