Monday, August 24, 2020

Using yum through socks5 proxy

This is useful when you have a server that is not allowed to go to the internet, but have an ssh connection to another server that is able to go to the internet (we can call it jumphost).


1. Setup a socks proxy on port 8888 (any port will do, 8888 is just my preference) via the jumphost

# ssh -D 8888 -fN user@jumphost


2. Append below line into yum.conf

# cat  >> /etc/yum.conf <<EOF

proxy=socks5h://localhost:8888

EOF


3. Yum away (or run the yum command). All yum command will now tunneled through jumphost

# yum update


4. Once done, kill the socks proxy connection

# kill -9 $(ps -ef | grep fN | grep -v grep | awk '{print $2}')


5. And remove the proxy setting in /etc/yum.conf

# sed -i '$d' /etc/yum.conf

No comments: