Question

I want to make when CentOS start in init 3 to show me my ip addr, before log in. For Example:

CentOS Realese 6.5(Final)
Kernel 2.6..
ip addr: 192.168.1.1

or something like that.

I make script which is:

    #!/bin/bash
    ifconfig eth0 | grep 'inet addr'

but, I don't know where I put it.

I try in rc.local (with "cat" and him path) but obviously it is not right place, or I make something wrong. And I try in /etc/issue , but and there maybe I make something wrong.

Was it helpful?

Solution 3

Place this code into /etc/rc.d/rc.local and install banner application tho show BIG ip address

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

SETCOLOR_SUCCESS="echo -en \\033[1;32m"
SETCOLOR_FAILURE="echo -en \\033[1;31m"
SETCOLOR_WARNING="echo -en \\033[1;33m"
SETCOLOR_NORMAL="echo -en \\033[0;39m"
SETCOLOR_BLUE="echo -en \\033[0;36m"

touch /var/lock/subsys/local

${SETCOLOR_BLUE}
IP=`/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'`
${SETCOLOR_NORMAL}
#IP=255.255.255.255
if [[ -z "${IP}" ]]; then
    ${SETCOLOR_FAILURE}
    echo "######################################################################"
    echo "##                                                                  ##"
    echo "##        Please setup networking and restart virtual machine!      ##"
    echo "##                                                                  ##"
    echo "######################################################################"
else
    ${SETCOLOR_WARNING}
    echo "Local IP is"
    COLUMNS=200 banner ${IP}
fi
${SETCOLOR_SUCCESS}
echo "Use root/password to login"
${SETCOLOR_NORMAL}

OTHER TIPS

On CentOS 7 and Debian 8 (and maybe other as well), just append the following line to /etc/issue

My IP address: \4

and that will resolve to the machine's IPv4 address. If you have multiple network interfaces and you want to pick one specific, you can specify it with

My IP address: \4{eth0}

I don't believe /etc/issue can be made to display IP addresses by itself which means you are probably going to need to rewrite your /etc/issue at boot time and possibly force login to reload to see it or something else of that general sort.

Update for newer OS versions: see PaoloC's answer here.

Refer to https://serverfault.com/a/594262/177172

I use the following (slightly modified):

#!/bin/sh
## https://serverfault.com/a/594262/177172

IPADDRS_TEXT="IP addresses of all external interfaces of this host:"
IPADDRS="$(hostname --all-ip-addresses)"

perl -i -p -0777 -e "s/^$IPADDRS_TEXT[^\n]*\n\n//m; s/$/\n$IPADDRS_TEXT $IPADDRS\n/ if length('$IPADDRS')>6" /etc/issue

Not sure where you can place this file on CentOS so that it is executed on interface/ip address change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top