Socks server for linux

Использование HTTP proxy и SOCKS в Linux

В Linux существует много полезных консольных команд, которые при необходимости хотелось бы запустить через proxy. Некоторые приложения имеют встроенную поддержку proxy, а некоторые нет. Далее описано как пользоваться востребованными утилитами через proxy, даже теми, которые этой поддержки не имеют.

curl: передача данных через proxy

curl имеет полноценную поддержку как HTTP proxy так и SOCKS.

Для тестирования возможно использовать proxy сервера из бесплатных списков (socks — sockslist.net, и HTTP proxy — proxyhttp.net). Проверка IP адреса будет производиться с помощью ресурса check-host.net

# Проверить HTTP proxy curl --proxy 11.22.33.44:5555 check-host.net/ip # Тоже самое, но если для HTTP proxy требуется авторизация curl --proxy 11.22.33.44:5555 -U username:password check-host.net/ip # Проверить socks4 curl --socks4 11.22.33.44:5555 check-host.net/ip # Проверить socks5 curl --socks5 11.22.33.44:5555 check-host.net/ip # Тоже самое, только преобразование имен идет также через SOCKS # (подробнее о преобразовании имен можно прочитать ниже в подразделе "DNS запросы через proxy") curl --socks5-hostname 11.22.33.44:5555 check-host.net/ip 

Часть параметров curl можно записать в файл ~/.curlrc:

socks5 = 11.22.33.44:5555 proxy-user = username:password user-agent = "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1" 

С помощью time и curl также можно замерить время отклика сервера:

# Без proxy: time curl check-host.net/ip # С proxy: time curl --socks5 11.22.33.44:5555 check-host.net/ip # Или любого сайта: time curl habrahabr.ru 

Результат будет выглядеть так:

real 0m0.307s user 0m0.000s sys 0m0.004s 

wget: закачка файлов через proxy

wget имеет встроенную поддержку proxy. Недостаток лишь в том, что только поддержку HTTP proxy. Для использования совместно с SOCKS рекомендуется использовать соксификатор dante.

 # Скачать файл через proxy: http_proxy="http://33.22.44.44:8080" wget http://www.google.com/favicon.ico Тоже самое, но для HTTPS https_proxy="http://33.22.44.44:8080" wget https://www.google.com/favicon.ico # Использовать proxy с авторизацией http_proxy="http://33.22.44.44:8080" wget --proxy-user=user --proxy-password=password http://www.google.com/favicon.ico 

Чтобы все время не указывать —proxy-user и —proxy-password можно их прописать в файл ~/.wgetrc:

proxy-user = username proxy-password = password user-agent = Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1 

ssh: доступ к серверам

Для доступа к серверам через ssh и proxy также лучше использовать соксификатор dante.

Читайте также:  Линукс выключить из консоли

Соксификатор dante

apt-get install dante-client # пример для Debian-based систем 
# Если требуется зайти по ssh на сервер SOCKS_PASSWORD="" SOCKS_SERVER="11.22.33.44:1080" socksify ssh myserver # Тоже самое, только если для подключения к соксу требуется авторизация SOCKS_USERNAME="user" SOCKS_PASSWORD="password" SOCKS_SERVER="11.22.33.44:1080" socksify ssh myserver # Пример с использованием IRC клиента - irssi SOCKS_PASSWORD="" SOCKS_SERVER="11.22.33.44:1080" socksify irssi # Тоже самое, только с использованием HTTP proxy с поддержкой метода CONNECT HTTP_CONNECT_PROXY="http://11.22.33.44:8080" socksify irssi 

С помощью socksify можно направить через proxy почти любое приложение, не только консольное.

Чтобы все время не вводить данные о proxy можно создать файл /etc/socks.conf
Пример для SOCKS:

Пример для HTTP proxy с авторизацией:

А также экспортировать переменные SOCKS_USERNAME и SOCKS_PASSWORD, если для SOCKS или HTTP proxy требуется авторизация:

export SOCKS_USERNAME="username" export SOCKS_PASSWORD="password" 

DNS запросы через proxy

Часто требуется чтобы и преобразование имен происходило через proxy. Если использовать dante, то запрос на преобразование имен идет и через proxy, и через именной сервер указанный в /etc/resolv.conf . Понять почему же идет два одинаковых запроса вместо одного не удалось. Поэтому можно предложить два варианта:
1) Закомментировать именные сервера в файле /etc/resolv.conf, чтобы преобразование имен шло только через proxy. Это отразится на всей системе.
2) Изменить /etc/resolv.conf и выставить именные сервера необходимой страны, или просто отличные от серверов провайдера. Например установить сервера Google:

nameserver 8.8.8.8 nameserver 8.8.4.4 

Чтобы данные не были перезаписаны именными серверами провайдера (при переподключении), можно запретить обновление списка именных серверов сетевому менеджеру (NetworkManager/wicd) или DHCP-клиенту (спасибо ergil за корректировку).

Или воспользоваться «грубым» методом — запрещением изменения файла /etc/resolv.conf:

sudo chattr +i /etc/resolv.conf 

Если есть какие-то дополнения, пожалуйста, напишите, это будет полезно узнать и применить.

Источник

How to setup a Socks5 Proxy server on Ubuntu with Dante

Dante is a socks5 server that you can use to setup a socks5 proxy on your ubuntu or debian machine. In this quick tutorial we shall learn how to setup dante and use authentication.

With authentication enabled, the dante proxy server would require all clients to provide login details in order to use the proxy server. This is a good idea.

Читайте также:  Linux odbc ini example

1. Install Dante on Ubuntu

The default Ubuntu repositories have the dante-server package but it is outdated. The version present is 1.1.19 which is quite old and also has some bugs. The authentication feature does not work properly.

If you don’t need authentication then you can install it.

sudo apt-get install dante-server

The version in repository was

# danted -v danted: dante v1.1.19

Known authentication issues

Like mentioned earlier, the authentication feature does not properly work with it. The log file shows the following error messages —

Mar 11 14:05:05 (1489241105) danted[5020]: pass(1): tcp/accept ]: username%[email protected] -> 104.131.115.128.1080: system username/password failed

Trying to test with curl shows the following error message —

$ curl -v -x socks5://username:[email protected]:1080 http://www.google.com/ * Trying 104.131.115.128. * User was rejected by the SOCKS5 server (1 1). * Closing connection 0 curl: (7) User was rejected by the SOCKS5 server (1 1).

Install newer version directly from .deb file

So we need to install a newer version. There is a ppa for dante-server at — https://launchpad.net/~dajhorn/+archive/ubuntu/dante

but it is no longer being maintained. But we can use the deb file from the ppa to install dante on Ubuntu 16.10

Download using the wget command:

# wget http://ppa.launchpad.net/dajhorn/dante/ubuntu/pool/main/d/dante/dante-server_1.4.1-1_amd64.deb

Install using gdebi command:

$ sudo apt-get install gdebi-core $ sudo gdebi dante-server_1.4.1-1_amd64.deb

2. Configure

The next task is to configure the dante server before starting it. The configuration file can be found here —

The contents should look similar to this —

# /etc/danted.conf logoutput: syslog user.privileged: root user.unprivileged: nobody # The listening network interface or address. internal: 0.0.0.0 port=1080 # The proxying network interface or address. external: eth0 # socks-rules determine what is proxied through the external interface. # The default of "none" permits anonymous access. socksmethod: username # client-rules determine who can connect to the internal interface. # The default of "none" permits anonymous access. clientmethod: none client pass < from: 0.0.0.0/0 to: 0.0.0.0/0 log: connect disconnect error >socks pass < from: 0.0.0.0/0 to: 0.0.0.0/0 log: connect disconnect error >

Now start the danted proxy server

Читайте также:  Linux system programming with python

Use the netstat command to check the port number

# netstat -nlpt | grep dant tcp 0 0 0.0.0.0:1080 0.0.0.0:* LISTEN 6342/danted

3. Create a User

Dante can use the system unix user accounts to authenticate the connecting clients. For this you should create a separate user. Any client that will be connecting to this proxy server will be sending the password in plain text over the network, so beware of that.

4. Test with curl

Once you have setup everything, its time to test that the proxy server is working as expected. Use the curl command to do this. Specify the username, password, server ip and port number and try fetching some url.

curl -v -x socks5://mike:mike@:1080 http://www.google.com/

If everything goes fine, you should see the html of google.com in the terminal. Now you can use the proxy inside of browsers.

Conclusion

Dante is a socks5 server that can be used as a proxy server. For instance you can setup an online linux server and use it as a proxy server to access other websites. Such proxy servers are useful when you need to change your ip address on the internet or access a website from a different geo location.

If you need an http proxy server or caching solution try Squid Proxy which supports http, https etc.

Resources

If you want to compile the latest version of dante from source then check out these links —

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

7 Comments

  1. Gerardo Sandrigam January 5, 2021 at 12:12 am Hello Friends I just install Dante Socks 1.4.02 version of Dante on Virtual Machine of my Pc with Virtual Box and Red Hat 8.3 , I finally finally I got the service to work but how can I do a test with user and password to port 1080 that I already configure in the sockd.conf file Regards

Источник

Оцените статью
Adblock
detector