ifconfig

Linux常用网络配置命令

谁都会走 提交于 2019-12-24 03:13:39
1. 查看网络接口信息 ifconfig 查看网络接口信息( /sbin/ifconfig ) ifconfig [ 网络接口 ] 查看指定网络接口信息 ifconfig -a 查看系统中所有网络接口的信息 2. 查看网关地址和路由信息 route 查看主机路由信息( /sbin/route ) route | grep default 显示默认网关地址 ping 目的主机地址 测试与其他主机的网络连接 Ctrl + C 结束 ping 命令执行 ping -c [ 测试数据包数量 ] [ 目的主机地址 ] 发送指定数量的数据包进行网测 traceroute [ 目的主机地址 ] 测试与其他主机的网络连接路径 3. 查看主机名称信息 hostname 查看当前主机的主机名称 hostname [soul.com] 更改主机名(重启后消失) vi /etc/sysconfig/network 更改主机名(重起后生效) ~# grep HOSTNAME /etc/sysconfig/network HOSTNAME=soul.com 4. 使用 DNS 服务器查询域名 nslookup 域名查询 exit 退出交换环境 5. ip 地址配置命令 网络设置 dhclient 从 DHCP 服务器中申请新的网络配置应用于当前 Linux 主机 ifconfig [ 网络接口名称 ] [ip

Get IP address from ifconfig using PHP

时光毁灭记忆、已成空白 提交于 2019-12-23 03:21:36
问题 I have the next php code: <?php $ip = shell_exec("/sbin/ifconfig | grep 'inet:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'"); echo $ip; ?> It works fine when I run it from the command line ( $php5 ip.php ), but when I run it from my browser it shows nothing ( http://localhost/ip.php ). By the way, I'm trying to print my IP address but whenever I use $_SERVER['SERVER_ADDR']; I get 127.0.0.1 . 回答1: It will work without colon next to 'inet' grep 'inet ' 回答2: I would write a bash

Get IP address from ifconfig using PHP

半世苍凉 提交于 2019-12-23 03:21:24
问题 I have the next php code: <?php $ip = shell_exec("/sbin/ifconfig | grep 'inet:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'"); echo $ip; ?> It works fine when I run it from the command line ( $php5 ip.php ), but when I run it from my browser it shows nothing ( http://localhost/ip.php ). By the way, I'm trying to print my IP address but whenever I use $_SERVER['SERVER_ADDR']; I get 127.0.0.1 . 回答1: It will work without colon next to 'inet' grep 'inet ' 回答2: I would write a bash

How to get an output formatted as “Interface: IP Address” from ifconfig on Mac

做~自己de王妃 提交于 2019-12-22 08:12:19
问题 I am trying to get the following formatted output out of ifconfig: en0: 10.52.30.105 en1: 10.52.164.63 I've been able to at least figure out how to get just the IP addresses (weeding out localhost) with the following command, but it's not sufficient for my requirements: ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}' Thanks! 回答1: This works on FreeBSD, which is at the heart of an apple :-) #!/bin/sh for i in $(ifconfig -l); do case $i in (lo0) ;; (*) set -- $

How can I fetch the ethernet port given the ip address?

谁都会走 提交于 2019-12-22 06:10:34
问题 I am trying to write a bash script to fetch the ethernet port of an interface whose IP address I know. I need to grab this from ifconfig but can't seem to be able to figure out how to go about it. Any ideas? Thanks. 回答1: A little messy but should work: /sbin/ifconfig | grep -B1 1.2.3.4 | awk '{print $1; exit}' Optionally, you could use the ip command which, when used with the -o|-oneline option, is a lot easier to parse. For example ip -o addr | awk '/1.2.3.4/{print $2}' 回答2: Replace 127.0.0

How can I fetch the ethernet port given the ip address?

浪子不回头ぞ 提交于 2019-12-22 06:10:03
问题 I am trying to write a bash script to fetch the ethernet port of an interface whose IP address I know. I need to grab this from ifconfig but can't seem to be able to figure out how to go about it. Any ideas? Thanks. 回答1: A little messy but should work: /sbin/ifconfig | grep -B1 1.2.3.4 | awk '{print $1; exit}' Optionally, you could use the ip command which, when used with the -o|-oneline option, is a lot easier to parse. For example ip -o addr | awk '/1.2.3.4/{print $2}' 回答2: Replace 127.0.0

ubuntu设置固定ip

十年热恋 提交于 2019-12-21 20:57:51
设定IP $sudo gedit /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.0.111 netmask 255.255.255.0 gateway 192.168.0.1 保存,并关闭gedit。 这样,IP并没有立即生效。需要执行 $sudo /etc/init.d/networking restart 这时候就能ping到局域网中的电脑了。但是上不了Internet,是因为没有设置DNS的原因。DNS信息保存在/etc/resolv.conf中,一旦更改,立即生效。 2)配置DNS: sudo gedit /etc/resolv.conf nameserver 202.107 . 117.11 保存并关闭,现在就可以上网了。 附网卡设置相关命令: 查看网卡信息: ifconfig 设定一个网卡IP:ifconfig eth1 192.168.1.10 netmask 255.255.255.0 重启网卡使设定生效:sudo /etc/init.d/networking restart 更改MAC地址:ifconfig eth0 hw ether xx:xx:xx:xx:xx:xx 查看路由相关信息:route -n

How to fetch the logical name of a NIC card given the ip address associated with it ?

泪湿孤枕 提交于 2019-12-21 19:26:09
问题 I am working on a shell script which needs to know the logical name (eth0, eth1, etc) associated with a given ip. The current procedure I am employing is to parse the output of ifconfig using filters and getting the NIC card associated with a given IP. I was wondering if there exists a simpler way or a direct pipelined linux command to get the above mentioned detail? 回答1: Take this: #!/bin/sh ip=192.168.1.10 iface=$(ip addr | grep $ip | awk '{print $NF}') echo "Iface is: ${iface}" 来源: https:/

Linux常用的网络命令

試著忘記壹切 提交于 2019-12-19 19:53:59
网络参数设置命令 所有时刻如果你想要做好自己的网络参数设置,包括IP参数、路由参数和无线网络等,就得要了解下面这些相关的命令才行。其中Route及ip这两条命令是比较重要的。当然,比较早期的用法,我们都是使用ifconfig的。 ? ifconfig:查询、设置网卡和IP网段等相关参数。 ? ifup、ifdown:这两个文件是Script,通过更简单的方式来启动网络接口。 ? Route:查询、设置路由表(Route table)。 ? ip:复合式的命令,能直接修改上述命令提到的功能。 ifconfig、ifup、ifdown 这 3个命令的用途都是启动网络接口,不过,ifup和ifdown仅就 /etc/sysconfig/network- scripts内的ifcfg-ethx(x为数字)进行启动或关闭的操作,并不能直接修改网络参数,除非手动调整ifcfg-ethx文件才行。至于 ifconfig则能直接手动给予某个接口IP或调整其网络参数。下面我们就分别来谈一谈。 1. ifconfig ifconfig主要是能手动启动、观察和修改网络接口的相关参数,能修改的参数非常多,包括IP参数及MTU等都能修改,他的语法如下: [root@linux ~]# ifconfig {interface} {up|down} 一 般来说,直接输入ifconfig就会列出目前已被启动的卡

Linux静态IP设置

一曲冷凌霜 提交于 2019-12-19 04:58:56
Linux静态IP设置 IP配置: /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=static HWADDR=00:26:18:0B:38:C0 ONBOOT=yes IPADDR=192.168.0.20 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 IP生效: /sbin/ifdown eth0 /sbin/ifup eth0 通知网关更新信息: /etc/init.d/network restart 配置DNS: vi /etc/resolv.conf nameserver 202.96.134.133 解决重启生效: chattr +i /etc/resolv.conf 改为只读 首先,先了解传统的网络配置命令: 1. 使用ifconfig命令配置并查看网络接口情况 示例1: 配置eth0的IP,同时激活设备: # ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up 示例2: 配置eth0别名设备 eth0:1 的IP,并添加路由 # ifconfig eth0:1 192.168.4.2 # route add –host 192.168.4.2 dev eth0:1 示例3:激活(禁用)设备 #