Solved IP Addresses in /etc/issue?

I am building out a VM to run my application and it should work immediately upon boot. Is there a way to have all IP addresses of em0 (IPv4 and IPv6) displayed in the /etc/issue?

My users will be somewhat non-technical users, so checking the IP address might not be the best option.
 
You can add this to your /etc/profile:

Code:
/sbin/ifconfig em0 | /usr/bin/awk '/inet/{print $2}'

This will print the em0 ips (v4 and v6) after user login.

I am not sure FreeBSD use /etc/issue, I know FreeBSD use /etc/motd.
 
I believe /etc/motd was upon authentication, right? I want something pre-authentication.
I would imagine /etc/profile would be after a user authenticates, nor prior.
 
If the users are connecting via ssh, then you can set Banner in sshd_config to point to a banner file that is shown before login.
 
They would not be able to ssh to the prompt to get the IP address to begin with.
But, even then, the assumption is that these are non-technical users who I do not (yet) want them to have to login and check ifconfig.
 
Quick and ugly, you could create a script in /usr/local/etc/rc.d called zz_ipaddress.sh (so it executes last) with appropriate shell commands to echo the information out. You may also want to use that same script to write to /etc/csh.logout in the case someone logs into the terminal. When that user logs out, the IP info will be displayed.
 
I'm a little puzzled here, if your users are non-technical then why bother showing them the IP address in the first place? What are you trying to achieve here? Just asking because I can't help get the impression that you're putting effort into something which might not work anyway.

I mean.. An IP address is just that, when talking about VM's then chances are high that it only gets a local IP address, which might even be fully unrelated to the host. Ergo: not something fully usable.
 
I'm a little puzzled here, if your users are non-technical then why bother showing them the IP address in the first place? What are you trying to achieve here? Just asking because I can't help get the impression that you're putting effort into something which might not work anyway.

I mean.. An IP address is just that, when talking about VM's then chances are high that it only gets a local IP address, which might even be fully unrelated to the host. Ergo: not something fully usable.
Maybe I should qualify that. They are not Unix users, so while they could log in and check the IP address, I would prefer they do not have to. This VM will run a web application, and the URL will be the IP address, ie https://198.51.100.0, but beyond that, they are not used to using a terminal. I am trying to reduce the possibility of PEBCAK :)

They will definitely have an Internal IP address. That is by design, the VM must run on an individual user's laptop so that it can be taken into an air-gapped environment - its is a business requirement. Otherwise, I'd run in Heroku/AWS.

Per pboehmer's suggestion, I might just write some code that updates the /etc/issue file at boot and periodically thereafter.

Either way, would be a nice feature to have a dynamic /etc/issue. I feel like I have seen this before somewhere...
 
Either way, would be a nice feature to have a dynamic /etc/issue. I feel like I have seen this before somewhere...
Have to disagree there a bit considering the fact that FreeBSD doesn't even use /etc/issue.

Even /etc/ssh/sshd_config makes this really clear with the PrintMotd option (see also sshd(8)).

Anyway, I'd look into login.conf(5) instead, specifically the login_prompt string. I don't know from mind (yet) how (and if) you can change that, but I'd start there. Especially considering the default login string in which it shows the current hostname. Can't help wonder if that can't be swapped for an IP address.

(edit):

Well, that was obviously a small mistake but that's what I get when I focus too much on one subject. The answer here is gettytab(5), see also /etc/gettytab. That defines the actual login string (I should have known considering that I'm well aware of the existence of getty):

Code:
93878 v1  Is+     0:00.00 /usr/libexec/getty Pc ttyv1
 1885 v2  Is+     0:00.00 /usr/libexec/getty Pc ttyv2
 1886 v3  Is+     0:00.00 /usr/libexec/getty Pc ttyv3
 1887 v4  Is+     0:00.00 /usr/libexec/getty Pc ttyv4
 1888 v5  Is+     0:00.00 /usr/libexec/getty Pc ttyv5
 1889 v6  Is+     0:00.00 /usr/libexec/getty Pc ttyv6
 1890 v7  Is+     0:00.00 /usr/libexec/getty Pc ttyv7
Anyway....

Looking into gettytab learns me that the login prompt is defined using im=. It even has codes which you can use, as seen by the default:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:
And there's also /etc/issue ;) But according to gettytab(5) this option is unused. It's also where I based my previous comment on.

Anyway, the only character sequences I managed to find were %d (current date & time), %h (hostname), %t (tty name), %m, %r, %s, %v (machine type, OS release, OS name, kernel version) and %% to get a literal %.

Now, here's where it becomes a little bit interesting: the hostname is normally obtained from gethostname(3) but it seems you can override it using the hn entry and edit it using the he string.

SO... My suggestion is to set something like in /etc/gettytab:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:hn=127.0.0.1
This will effectively replace the hostname in the login prompt with the IP address (127.0.0.1 in my example).

Do note that this is not dynamic. After all: in order for /etc/gettytab to get refreshed / become active you'd have to restart the getty daemon first. This is the other reason why I don't really see much use in some kind of dynamic /etc/issue file, because it would only apply to restarted listeners.
 
You can do this by introducing a new script into /usr/local/etc/rc.d, let's call it update-issue:
Code:
#!/bin/sh

# PROVIDE: update-issue
# REQUIRE: NETWORKING syslogd
# KEYWORD:

. /etc/rc.subr

/sbin/ifconfig > /etc/issue
Reboot / restart init.

As ShelLuser says though, nothing dynamic.
 
Have to disagree there a bit considering the fact that FreeBSD doesn't even use /etc/issue.

Even /etc/ssh/sshd_config makes this really clear with the PrintMotd option (see also sshd(8)).

Anyway, I'd look into login.conf(5) instead, specifically the login_prompt string. I don't know from mind (yet) how (and if) you can change that, but I'd start there. Especially considering the default login string in which it shows the current hostname. Can't help wonder if that can't be swapped for an IP address.

(edit):

Well, that was obviously a small mistake but that's what I get when I focus too much on one subject. The answer here is gettytab(5), see also /etc/gettytab. That defines the actual login string (I should have known considering that I'm well aware of the existence of getty):

Code:
93878 v1  Is+     0:00.00 /usr/libexec/getty Pc ttyv1
 1885 v2  Is+     0:00.00 /usr/libexec/getty Pc ttyv2
 1886 v3  Is+     0:00.00 /usr/libexec/getty Pc ttyv3
 1887 v4  Is+     0:00.00 /usr/libexec/getty Pc ttyv4
 1888 v5  Is+     0:00.00 /usr/libexec/getty Pc ttyv5
 1889 v6  Is+     0:00.00 /usr/libexec/getty Pc ttyv6
 1890 v7  Is+     0:00.00 /usr/libexec/getty Pc ttyv7
Anyway....

Looking into gettytab learns me that the login prompt is defined using im=. It even has codes which you can use, as seen by the default:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:
And there's also /etc/issue ;) But according to gettytab(5) this option is unused. It's also where I based my previous comment on.

Anyway, the only character sequences I managed to find were %d (current date & time), %h (hostname), %t (tty name), %m, %r, %s, %v (machine type, OS release, OS name, kernel version) and %% to get a literal %.

Now, here's where it becomes a little bit interesting: the hostname is normally obtained from gethostname(3) but it seems you can override it using the hn entry and edit it using the he string.

SO... My suggestion is to set something like in /etc/gettytab:

Code:
default:\
        :cb:ce:ck:lc:fd#1000:im=\r\n%s/%m (%h) (%t)\r\n\r\n:sp#1200:\
        :if=/etc/issue:hn=127.0.0.1
This will effectively replace the hostname in the login prompt with the IP address (127.0.0.1 in my example).

Do note that this is not dynamic. After all: in order for /etc/gettytab to get refreshed / become active you'd have to restart the getty daemon first. This is the other reason why I don't really see much use in some kind of dynamic /etc/issue file, because it would only apply to restarted listeners.

Very elegant solution! I like it! However, I did not see from your explanation or gettytab(5) how to populate the "hn" variable with the current IP address. Am I missing it? :)
 
Hi all, just wanted to circle back on the approach I decided to take. It is properly not the most efficient approach, but it works.

I took leebrown66's advice and make /usr/local/etc/rc.d/update-issue. Here are the contents:

Code:
#!/bin/sh

# PROVIDE: update-issue
# REQUIRE: NETWORKING syslogd
# KEYWORD:

. /etc/rc.subr

IPADDRESSESV4=$(ifconfig em0 | grep inet | grep -v inet6 | awk '{print $2}')
IPADDRESSESV6=$(ifconfig em0 | grep inet6 | grep -v fe80 | awk '{print $2}')

printf "\033[2J" > /etc/issue
cat /root/issue-top >> /etc/issue

for IPADDRESS in $IPADDRESSESV4;
        do
                LENGTH=$(echo $IPADDRESS | wc -c)
                printf "\| https://$IPADDRESS" >> /etc/issue
                /usr/local/bin/perl -e "print ' ' x (70-$LENGTH); print \"\|\n\"" >> /etc/issue
        done;

for IPADDRESS in $IPADDRESSESV6;
        do
                LENGTH=$(echo $IPADDRESS | wc -c)
                printf "\| https://[$IPADDRESS]" >> /etc/issue
                /usr/local/bin/perl -e "print ' ' x (68-$LENGTH); print \"\|\n\"" >> /etc/issue
        done;

echo "+------------------------------------------------------------------------------+" >> /etc/issue
echo "" >> /etc/issue

You'll notice that I am doing some insanity with the IP address content-length and adding that many spaces. That's because I have some ASCII art that extends to the size of the terminal (80 characters)

The initial clear screen (the printf) might be unnecessary. Also, I should probably have the contents of /root/issue-top within the script, but that's secondary.

Is it efficient? Probably not. But it works! Hope this helps someone in the future.
 
Back
Top