0

I want to be able to do:

  1. ssh user_name@bla where bla points to a specific ip address
  2. Same, but from browser, I want to access http://blabla where blabla is another specific ip address with a port (i.e. 1.2.3.4:5678)

Is there a local DNS I can setup?

Working on 16.04

EDIT:

(1) can be easily achieved by adding the following line to /etc/hosts file: IP_ADDR bla and then ping bla translates into ping IP_ADDR. However (2) still eludes me.

Without a port, its much the same like (1), but adding a port makes it more complicated

CIsForCookies
  • 1,089
  • 11
  • 30
  • 1
    There is no way to make a host name include the port number. However, you could setup the web server over at `blabla` so that requests for `http://blabla` are received at port 80 and redirected to `localhost:5678`. That can be done with e.g. Apache configuration files. – Jos Jun 24 '20 at 14:41
  • 3
    Another approach would be to do port forwarding on host `blabla` using `iptables`. – Jos Jun 24 '20 at 14:42
  • So basically, all the configurations are done on the server and not the client? – CIsForCookies Jun 24 '20 at 15:09
  • For SSH, you can use your client-side `~/.ssh/config` file - see for example [Permanently store addresses when using SSH](https://askubuntu.com/a/666798/178692) – steeldriver Jun 24 '20 at 15:21
  • @steeldriver ssh I have already figured out. The http with custom port is the issue – CIsForCookies Jun 24 '20 at 15:30

1 Answers1

1

You can setup DNS for this, but much easier for local use is editing the /etc/hosts file:

127.0.0.1   localhost
127.0.1.1   Yourhostname 

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

192.168.124.99 bla
192.168.124.100 blabla 
192.168.124.107 blablabla

Starting from a fresh /etc/hosts file, leave the lines that are already there alone, add your hostname as 127.0.1.1, and add others as needed. Save the file. It will work instantly.

EDIT this answer was posted before you added the /etc/hosts suggestion yourself.

Jos
  • 28,156
  • 8
  • 82
  • 88
  • Thanks! but as I said in my edit, I've done this part. I can't seem to go to http:// blabla where blabla is configured to be 1.2.3.4:5678 in etc/hosts – CIsForCookies Jun 24 '20 at 14:38