linux 系统获取当前登陆ip地址的几种方法

linux 系统获取当前登陆ip地址的几种方法,第1张

1

[root@localhost test]# echo $SSH_CLIENT |awk ' { print $1 }'

111.161.8.26

2

[root@localhost test]# who am i |awk ' {print $5 }'

(111.161.8.26)

3 以下是2种不太完整的方法

[root@localhost test]# w | awk '{ print $3 }'

8

FROM

111.161.8.26

[root@localhost test]# finger | awk '{ print $7 }'

Office

(111.161.8.26)

1、连接上相应的linux主机,进入到等待输入shell指令的linux命令行状态下。

2、在linux命令行下输入shell指令:ip addr eth0。

3、键盘按“回车键”运行shell指令,此时会查询到eth0网卡的ip地址。。

1.首先在Linux系统下设置静态的IP地址

vim /etc/network/interfaces #编辑网网卡配置文件

auto lo

iface lo inet loopback

auto eth0 #开机自动连接网络

iface eth0 inet static #static表示使用固定ip,dhcp表述使用动态ip

address 192.168.21.168 #设置ip地址

netmask 255.255.255.0 #设置子网掩码

gateway 192.168.21.2 #设置网关

ctrl+o #保存配置

ctrl+x #退出

2.在/etc/profile 加入脚本

vim /etc/profilegrep -v "hostname(指定的域名)" /etc/hosts > ~/hosts_temp 

cat ~/hosts_temp > /etc/hosts 

LC_ALL=C ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' |cut -d: -f2 | awk '{ print $1}' >> /etc/hosts

3.重启网络使设置生效

/etc/init.d/networking restart #重启网络


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/yw/7444932.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存