Display the IP address of the current server in the Shell Command Prompt

 At work, it is often necessary to connect to multiple servers at the same time through ssh from the local terminal, so it is necessary to open multiple terminal labels. In this case, it is always difficult to remember which label corresponds to which server. It would be a little troublesome to check the IP every time ifconfig.

 

The most convenient way to solve this problem is to display the IP address directly in the shell prompt.

The environment variable PS1 can configure the display effect of the prompt. To display the IP address, the following settings can be used:

export PS1="[\u@`/sbin/ifconfig eth0 | sed -nr 's/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` \W]\$"

To make the configuration permanent, you need to write it to ~/.bashrc or modify /etc/bashrc with root privileges.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326680790&siteId=291194637