Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6339295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:37:26+00:00 2026-05-24T19:37:26+00:00

Is there a way to echo only the server ip adress from Bash? I

  • 0

Is there a way to echo only the server ip adress from Bash? I am on a Linux/Debian6.

My intent is to write to “/etc/hosts” the pair domain_name IP for each new domain I register in the server.

As this bash script will be opened for public use, I am trying to find a way of getting this information via cli.

CONCLUSION:

This is the final code, based on the clues my friends helped me with:

newhost() {
    DMN=$1
    X=`ifconfig | grep Bcast`
    Y=`echo "${X#*:}"`
    DNS=`echo "${Y%\  B*}"` # server DNS(207.112.37.222)
    H='/etc/hosts' #hostfile
    PAIR="$DNS\t$DMN"
    if grep -i --silent "$DMN" "$H"; then
        echo -e "$DMN already exists in $H"
    else
        bash <<EOF
echo -e "$PAIR" >> "$H"
EOF
        echo -e "$PAIR added to $H"
    fi
}

By the way, Isn’t it funny that some born-already-smart dudes voted to close the question?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:37:27+00:00Added an answer on May 24, 2026 at 7:37 pm

    use:

    ifconfig – your ip will be after the inet addr: in this case 1.1.1.1

    sample output:

    root@server [~]# ifconfig
    eth0      Link encap:Ethernet  HWaddr 00:0A:E4:89:0B:97
              inet addr:1.1.1.1  Bcast:1.1.1.63  Mask:255.255.255.192
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1/or modify
              RX packets:14804377317 errors:0 dropped:0 overruns:0 frame:0
              TX packets:11766937374 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:13799286299902 (12.5 TiB)  TX bytes:4891709752100 (4.4 TiB)
              Interrupt:169 Memory:fa000000-fa012800  will be useful,
    

    http://www.debianadmin.com/network-interface-configuration-using-ifconfig.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any way so that i can echo password when asked for in
I'm just wondering if there is a quick way to echo undefined variables without
Is there way in next piece of code to only get the first record?
Is there a way to enforce constraint checking in MSSQL only when inserting new
Is there a way to make a read-only property of an object in PHP?
Is there a way to get the integer that wc returns in bash? Basically
Is there a way to test if a collection is already initialized? try-catch only?
is there way thats i can preselect an item when the page loads or
Is there any way to check whether a file is locked without using a
Is there a way to find the name of the program that is running

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.