Results 1 to 7 of 7

Thread: Telnet by hostname without modifying /etc/hosts file

  1. #1
    Member
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    3

    Default Telnet by hostname without modifying /etc/hosts file

    Hi all,

    I have several devices in my network and I have a file with the name / ip of each device, is there any way i can execute a telnet to that file and execute the line I want so i can access the device I need?

    e.i

    hosts
    1.1.1.1 main
    2.2.2.2 smpt

    telnet hosts main

    Thanks all

  2. #2
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Hi,

    If you want to access network device by name , then you just need to configure "/etc/hosts" file as below.
    Code:
    192.168.1.1   router
    192.168.1.100 switch1
    after that you can simply do
    HTML Code:
    ping router
    and
    HTML Code:
    telnet switch1
    Rahul Patil <http://www.linuxian.com>

  3. #3
    Member
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    3

    Default

    Quote Originally Posted by Rahul.Patil View Post
    Hi,

    If you want to access network device by name , then you just need to configure "/etc/hosts" file as below.
    Code:
    192.168.1.1   router
    192.168.1.100 switch1
    after that you can simply do
    HTML Code:
    ping router
    and
    HTML Code:
    telnet switch1
    The issue is i dont have root or change the hosts file.

  4. #4
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Quote Originally Posted by opnine View Post
    The issue is i dont have root or change the hosts file.
    You can use alias as below
    Code:
    alias telnet_router 'telnet 192.168.1.1'
    in your ~/bashrc file

    Or you can use below function [ finally after some R&D , i created below function , just use it. may be some correction from Master ]

    PHP Code:
    function do_telnet () {
    # just copy and past this fucntion ~/.bashrc file.
    # then run "source ~/.bashrc" command to reload function or just logout and login
    # then just run "do_telnet router" command to connect router or host
    #

    [ $# -eq 0 ] && echo "Please give hostname to connect destination" || {
    . ~/.hosts  # path of host file
                            # in this file keep entry as below
                            # router=192.168.1.1   # without hash sign(#)
                            # switch=192.168.1.100
                            
    eval telnet \$$@
    }


    Rahul Patil <http://www.linuxian.com>

  5. #5
    Member
    Join Date
    Jun 2010
    Posts
    60
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Rep Power
    3

    Default

    Quote Originally Posted by Rahul.Patil View Post
    You can use alias as below
    Code:
    alias telnet_router 'telnet 192.168.1.1'
    in your ~/bashrc file

    Or you can use below function [ finally after some R&D , i created below function , just use it. may be some correction from Master ]

    PHP Code:
    function do_telnet () {
    # just copy and past this fucntion ~/.bashrc file.
    # then run "source ~/.bashrc" command to reload function or just logout and login
    # then just run "do_telnet router" command to connect router or host
    #

    [ $# -eq 0 ] && echo "Please give hostname to connect destination" || {
    . ~/.hosts  # path of host file
                            # in this file keep entry as below
                            # router=192.168.1.1   # without hash sign(#)
                            # switch=192.168.1.100
                            
    eval telnet \$$@
    }


    Fisrt of all thank you for all your time,, and please let me ask,, for the script you send me I have to make changes in the host file?

    THanks !!

  6. #6
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default

    Quote Originally Posted by opnine View Post
    Fisrt of all thank you for all your time,, and please let me ask,, for the script you send me I have to make changes in the host file?

    THanks !!
    you don't need to do any changes in "/etc/hosts" file, it's your own host file : ~/hosts
    Rahul Patil <http://www.linuxian.com>

  7. #7
    Senior Member Rahul.Patil's Avatar
    Join Date
    Feb 2012
    Location
    Mumbai india
    Posts
    447
    Thanks
    10
    Thanked 46 Times in 43 Posts
    Rep Power
    6

    Default back with New Solution!!!

    Hey,

    I am back with New Solution

    Code:
    echo "router 10.0.0.1" >> ~/my_hosts
    export HOSTALIASES=~/my_hosts
    then just use
    Code:
    telnet router
    and for permanent save hostaliases append HOSTALIASES=~/my_hosts in ~/.bashrc
    Code:
    echo "export HOSTALIASES=~/my_hosts" >> ~/.bashrc
    Note:- Make sure alias name does not include with (.) dot and any special character
    Last edited by Rahul.Patil; 10th February 2013 at 08:19 PM.
    Rahul Patil <http://www.linuxian.com>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Update /etc/hosts file on multiple servers under Linux / Unix OSES
    By vaibhav.kanchan in forum Shell scripting
    Replies: 1
    Last Post: 8th October 2012, 10:15 PM
  2. How to specify hostname while installing a package
    By reshmi01 in forum Ubuntu / Debian
    Replies: 1
    Last Post: 14th February 2011, 09:09 AM
  3. Can't ping hostname
    By satimis in forum Networking, Firewalls and Security
    Replies: 1
    Last Post: 25th September 2008, 12:04 AM
  4. /etc/hosts file
    By ricc in forum Linux software
    Replies: 1
    Last Post: 8th May 2007, 07:32 PM
  5. set up hostname in ubuntu linux
    By raj in forum Linux software
    Replies: 1
    Last Post: 20th December 2006, 02:51 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41