Solved How to launch Firefox through a proxy server.

Hello.

I've configured a proxy server inside an Ubuntu bhyve/vm and I want to connect to it through Firefox using the terminal on FreeBSD,instead of going on the Firefox setting and adding the proxy informations manually or pressing the "enable" button manually. Yes,I like to script everything as much as I can.

I've found a repository that contains a script that helps to setup a SOCKS5 proxy server on an Ubuntu system. The server uses dante-server and supports username/password authentication.

I have virtualized Ubuntu with bhyve and I've followed the instructions explained in the repository :

https://github.com/saaiful/socks5

basically,inside my Ubuntu 23.04 system (that has IP number = 192.168.10 and network interface = enp0s13) I did :

Code:
# wget https://raw.githubusercontent.com/saaiful/socks5/main/socks5.sh
# sudo bash socks5.sh

# nano /etc/danted.conf

logoutput: /var/log/danted.log
internal: 0.0.0.0 port = 1080
external: enp0s13
method: username none
user.privileged: root
user.notprivileged: nobody
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

# systemctl enable danted
# systemctl start danted

I checked that it worked on FreeBSD (in FreeBSD the IP assigned is 192.168.1.5) :

Code:
# curl -x socks5://192.168.1.10:1080 https://ifconfig.me

87.14.68.111 ---> it works. it is the IP assigned to Ubuntu.

at this point,on Firefox I have configured the SOCKS5 proxy using the IP assigned to Linux and the port used by the script :


Istantanea_2024-06-14_16-23-22.png



and boom. It worked like I wanted. But there is the last thing that I want to do,I want to automate and speed up the procedure. I would like to connect to the proxy through Firefox in FreeBSD using the terminal,instead of going on the Firefox setting and enabling the proxy there.

Maybe I found how to do that by reading this old thread :


I edited the /usr/local/etc/tsocks.conf file like this :

Code:
# Local networks
# For this example this machine can directly access 192.168.1.0/255.255.255.0
# (192.168.1.*) and 10.0.0.0/255.0.0.0 (10.*)

local = 192.168.1.0/255.255.255.0
local = 10.0.0.0/255.0.0.0

# Default server
# For connections that aren't to the local subnets or to 150.0.0.0/255.255.0.0
# the server at 192.168.0.1 should be used (again, hostnames could be used
# too, see note above)

server = 192.168.1.10
# Server type defaults to 4 so we need to specify it as 5 for this one
server_type = 5
# The port defaults to 1080 but I've stated it here for clarity
server_port = 1080

and finally I tried to launch Firefox with tsocks :

Code:
tsocks firefox

Unfortunately this time my IP isn't changed. So it didn't work.
 
Maybe I've understood how you want to solve this problem. Do you want to leave the proxy configured and enabled on the new profile forever ?
 
yes just create another firefox profile for the proxy
and change the network settings in that profile to use the proxy

then you can switch profiles to either use the proxy or not

or you could just use 1 profile and change the network proxy in the firefox settings
or use an extension

 
I'm going to create another profile. Let's see if it works. I used proxy toggle on my experiment. But when I want to enable the proxy I should press on the "enable" button. Instead,I want to make something through the terminal to enable the proxy.
 
I want to make something through the terminal to enable the proxy.
Try HTTP_PROXY, HTTPS_PROXY environment variables before starting firefox from command line, see https://support.mozilla.org/en-US/questions/1440833 .

Example
Code:
 $ env http_proxy="http://PROXY_SERVER:PORT"    firefox
 $ env HTTP_PROXY="http://PROXY_SERVER:PORT"    firefox
 $ env https_proxy="https://PROXY_SERVER:PORT"   firefox

 $ env http_proxy="http://USER:PASSWORD@PROXY_SERVER:PORT"   firefox
 $ env https_proxy="https://USER:PASSWORD@PROXY_SERVER:PORT"   firefox

To shorten the command a shell alias can be created.

See also fetch(1) ENVIRONMENT for other variables.
 
None of these work :

Code:
env http_proxy="http://192.168.1.10:1080" firefox -P
env https_proxy="https://192.168.1.10:1080" firefox -P
env http_proxy="192.168.1.10:1080" firefox -P
env https_proxy="192.168.1.10:1080" firefox -P

but it works if I keep enabled the proxy using the extension "proxy toggle" on a new profile.
 
These even don't work :

Code:
env https_proxy="192.168.1.10:1080" firefox -P default-proxy
env https_proxy="https://192.168.1.10:1080" firefox -P default-proxy

anyway,I don't need to use that form. It works placing the proxy informations on the profile n.2 keeping it enabled forever.
 
proxychains-ng is another option



after you configure proxychains-ng you can run Firefox like this
Code:
proxychains-ng firefox
 
Back
Top