3
1
I was able to do in Ubuntu by editing the file:
/etc/rc.local
and add:
IP=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')
echo "IP: $IP" > /etc/issue
In Arch, this file does not exist "/etc/rc.local" and after some search I found that I have to create this file:
/etc/systemd/system/rc-local.service
Content:
[Unit]
Description=/etc/rc.local compatibility
[Service]
Type=oneshot
ExecStart=/etc/rc.local
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
Then Create "/etc/rc.local".
Content:
IP=$(/sbin/ip route get 1 | awk '{print $NF;exit}')
echo "IP: $IP" > /etc/issue
exit 0
Then Make it Executable:
sudo chmod +x /etc/rc.local
And finally start/test:
sudo systemctl start rc-local.service
Getting the error:
Job for rc-local.service failed because the control process exited with error code.
See "systemctl status rc-local.service" and "journalctl -xe" for details.
Output of systemctl status rc-local.service
:
* rc-local.service - /etc/rc.local Compatibility
Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2016-06-10 02:52:17 AST; 1min 59s ago
Process: 760 ExecStart=/etc/rc.local (code=exited, status=203/EXEC)
Jun 10 02:52:17 maro systemd[1]: Starting /etc/rc.local Compatibility...
Jun 10 02:52:17 maro systemd[1]: rc-local.service: Control process exited, code=exited status=203
Jun 10 02:52:17 maro systemd[1]: Failed to start /etc/rc.local Compatibility.
Jun 10 02:52:17 maro systemd[1]: rc-local.service: Unit entered failed state.
Jun 10 02:52:17 maro systemd[1]: rc-local.service: Failed with result 'exit-code'.
Output of journalctl -xe
:
-- Unit rc-local.service has begun starting up.
Jun 10 02:52:17 maro systemd[760]: rc-local.service: Failed at step EXEC spawning /etc/rc.local: Exec format error
-- Subject: Process /etc/rc.local could not be executed
-- Defined-By: systemd
Update:
- Added
#!/bin/bash
to/etc/rc.local
sudo systemctl daemon-reload
sudo systemctl start rc-local.service
- Now I am not getting any errors! but:
sudo systemctl status rc-local.service
Output:rc-local.service - /etc/rc.local Compatibility Loaded: loaded (/etc/systemd/system/rc-local.service; enabled; vendor preset: disabled) Active: inactive (dead) since Fri 2016-06-10 13:13:04 AST; 3s ago Process: 488 ExecStart=/etc/rc.local (code=exited, status=0/SUCCESS)
Jun 10 13:13:04 maro systemd[1]: Starting /etc/rc.local Compatibility... Jun 10 13:13:04 maro systemd[1]: Started /etc/rc.local Compatibility.
Tried to reboot and before login it says:
rtnetlink answers network is unreachable
At Login screen: it shows "IP:" only without showing the machine IP. Once logging in and ping google for example, internet is working with no problem and machine is accessible over LAN.
sudo env -i /etc/rc.local
= No outputip route get 1 | awk '{print $NF;exit}'
which is used in/etc/rc.local
= 192.168.0.103
Output of nav
:
XDG_SESSION_ID=c2
TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=192.168.0.100 64436 22
SSH_TTY=/dev/pts/0
USER=maro
MAIL=/var/spool/mail/maro
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
PWD=/home/maro
LANG=C
SHLVL=1
HOME=/home/maro
LOGNAME=maro
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
SSH_CONNECTION=192.168.0.100 64436 192.168.0.103 22
XDG_RUNTIME_DIR=/run/user/1000
_=/usr/bin/env
Edited /etc/systemd/system/rc-local.service
:
Removed four settings after ExecStart.
I have also tried changing:
Type=forking
Status still saying: Active: inactive (dead)
It appears that you are wanting to display the IP address, not the IP, as you asked for in the question. You only have two possible IPs: IPv4 and IPv6. – Ron Maupin – 2016-06-10T00:29:34.147
@RonMaupin, Sorry for the mistake, I want to display the internal IP address. Is there any mistake in my steps or bash code? – Maro – 2016-06-10T01:49:34.410