Forked from sampowers/map_remote_ipmi_ports_to_loopback_ip.sh
Created
April 22, 2021 19:03
-
-
Save mariusvw/6898cb3445e3a3e127d2fc075551b9ae to your computer and use it in GitHub Desktop.
SSH tunnel 127.0.0.2 to supermicro IPMI system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
# | |
# Purpose: Run on a workstation to make a remote IPMI controller available at http://127.0.0.2:80/ | |
# Only does port mapping. IPMI controllers may have their own taxing browser requirements. | |
# Requires that you have a shell on a host that is on the same network as your IPMI interface. | |
shell='user@ssh-host-on-ipmi-network' | |
# IPMI controller's IP address (on networks attached to your ssh host). | |
ipmihost='192.168.1.16' | |
# An additional address which we will later add as an alias on the loopback interface. | |
# This allows you to pretend that 127.0.0.2 is the address of your IPMI controller. | |
ifalias='127.0.0.2' | |
# The host I used this script with only required the following ports, for the features I was using. Yours may require more. | |
ports="80 443 623 5900 5901 5120 5123 8889" | |
# | |
# Forward each known IPMI port to the specified IPMI host-address using | |
# SSH TCP Forwarding as described in http://manpages.ubuntu.com/manpages/zesty/en/man1/ssh.1.html#contenttoc5 | |
# Build the SSH forwarding args, adding a -L [bind_address:]port:host:hostport argument for each port. | |
# | |
for p in $ports; do | |
fwportspec=" ${fwportspec} -L $ifalias:$p:$ipmihost:$p " | |
done | |
# | |
# Add an extra IP address that SSH will bind to for listening to the local forwarding ports. | |
# | |
sudo ifconfig lo0 alias $ifalias | |
# | |
# Open the ssh connection to the host that is on the same network as your IPMI interface. | |
# Puts SSH in verbose mode and enables compression for some reason. This does the port forwarding over ssh channels. | |
# | |
# As long as your shell to the remote host is open, you can browse to http://127.0.0.2:80 and access the IPMI login page. | |
echo "Using shell $shell to map IPMI-related ports on host $ipmihost to 127.0.0.2. http://127.0.0.2:80/" | |
sudo ssh -v -C $fwportspec $shell | |
sleep 1 # I don't remember why this is here. | |
sudo ifconfig lo0 -alias $ifalias # Remove the extra IP from the loopback interface. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment