【转载】kali ip地址和dns配置
https://blog.51cto.com/2042617/1612788
临时修改ip地址
<span style="color:#333333"><span style="color:#333333"><span style="color:#ffffff !important"><code class="language-bash"><span style="color:#dd4a68">ifconfig</span> eth0 up //端口启用
<span style="color:#dd4a68">ifconfig</span> eth0 down //端口关闭
<span style="color:#dd4a68">ifconfig</span> eth0 192.168.1.10 //只修改ip地址
<span style="color:#dd4a68">ifconfig</span> eth0 192.168.1.10/24 或者 <span style="color:#dd4a68">ifconfig</span> eth0 1.1.1.1 netmask 255.0.0.0 //修改ip地址和掩码</code></span></span></span>
临时修改网关
<span style="color:#333333"><span style="color:#333333"><span style="color:#ffffff !important"><code class="language-bash">route //查看路由表
<span style="color:#dd4a68">netstat</span> -rn //查看路由表
route del default eth0 //删除eth0上的默认路由
route add default gw 192.168.1.1 //添加默认路由</code></span></span></span>
永久修改ip地址和网关
进入配置文件
<span style="color:#333333"><span style="color:#333333"><span style="color:#ffffff !important"><code class="language-bash">/etc/network/interfaces
<span style="color:slategray"># This file describes the network interfaces available on your system</span>
<span style="color:slategray"># and how to activate them. For more information, see interfaces(5).</span>
<span style="color:slategray"># The loopback network interface</span>
auto lo
iface lo inet loopback
<span style="color:slategray"># The primary network interface</span>
allow-hotplug eth0
iface eth0 inet dhcp
<span style="color:slategray"># This is an autoconfigured IPv6 interface</span>
iface eth0 inet6 auto
修改为:
<span style="color:slategray"># This file describes the network interfaces available on your system</span>
<span style="color:slategray"># and how to activate them. For more information, see interfaces(5).</span>
<span style="color:slategray"># The loopback network interface</span>
auto lo
iface lo inet loopback
<span style="color:slategray"># The primary network interface</span>
allow-hotplug eth0
auto eth0 //增加了该选项,因为使用networking restart时系统启动 auto的网卡,如不加上则启动无反应
iface eth0 inet static //配置了static 为静态ip
address 192.168.1.4 //设置ip地址
netmask 255.255.255.0 //设置掩码
gateway 192.168.1.1 //设置网关
<span style="color:slategray"># This is an autoconfigured IPv6 interface</span>
iface eth0 inet6 auto</code></span></span></span>
配置dns
<span style="color:#333333"><span style="color:#333333"><span style="color:#ffffff !important"><code class="language-bash">/etc/resolv.conf
nameserver 202.106.0.20
nameserver 202.106.46.151
修改为:
nameserver 202.106.0.20
nameserver 202.106.46.151
nameserver 8.8.8.8</code></span></span></span>
重启网卡
linux下修改了IP地址需要重启网卡才行,重启网卡命令如下:# /etc/init.d/network restart
# service network restart
如果在本机上重启可以用下面命令 :
# ifconfig eth0 down
# ifconfig eth0 up
参考 Kali Linux渗透测试系统初始化设置指南
http://www.secpulse.com/archives/32875.html
笔者在渗透测试过程中经常会用到Metpasploit,如果不是静态IP而是DHCP分配的IP,在每次用Metasploit渗透时都需要在路由器里修改转发规则,个人感觉比较麻烦(懒)。
01.打开/etc/network/interfaces文件,将底部的iface eth0 inetdhcp改为iface eth0 inet static,allow-hotplug eth0改为auto eth0,添加address(IP地址)、netmask(子网掩码)、gateway(网关),具体请参照下表进行修改 。
02.打开/etc/resolv.conf文件,设置首选DNS、备用DNS(当地DNS,也可用114 DNS、Google DNS等公共DNS)。
03.终端命令行下重启网络:service networking restart或 /etc/init.d/networking restart 。
/etc/network/interfaces | /etc/resolv.conf |
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5).# The loopback network interface auto lo iface lo inet loopback# The primary network interface auto eth0 iface eth0 inet static # static表示使用固定ip,dhcp表示使用动态ip address 192.168.1.10 # 设置ip地址:192.168.1.10 netmask 255.255.255.0 # 设置子网掩码:255.255.255.0 gateway 192.168.1.1 # 设置网关:192.168.1.1 | nameserver 114.114.114.114 # 设置首选DNS nameserver 8.8.8.8 # 设置备用DNS |
注1:修改/etc/network/interfaces(网卡配置文件)、/etc/resolv.conf(DNS配置文件)请先做好备份,以免出问题 。
注2:# The loopback network interface这处内容不能删除或注释掉,否则即使能上网,也能获取到IP地址,但是ping不通本地127.0.0.1地址导致postgresql等服务不能正常启动,Metasploit启动时也会提示错误信息 。
注3:设置静态IP地址可能导致×××连接无反应,这时请将 # The primary network interface这处所有内容用#注释掉,然后使用service networking restart命令重启网络或reboot命令重启计算机 。