java实现网络配置,主要是往shell传递命令,例如:
Runtime.getRuntime().exec("dhclient ....");
有线wlan,这里有线设备名称为eth0(有关有线和无线设备可以在目录/sys/class/net/目录下看到)
主要配置文件:
/etc/network/interfaces 这个文件是保存ip,netmask,gateway信息的(包括静态和动态),实时生效的
/etc/resolv.conf 这个文件是保存DNS服务器信息的,实时生效
/etc/hosts 、/etc/hostname 在基于debian的linux系统中,修改主机名称,需要修改这两个文件,必须重启才能生效
设置自动获取IP
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo dhclient eth0
执行完上述命令以后,查看/etc/network/interfaces :
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
#iface eth0 inet static
查看/etc/resolv.conf :
nameserver 192.168.200.200
nameserver 192.168.200.240
修改主机名:
同时修改/etc/hosts 、/etc/hostname这两个文件即可
设置自定义IP
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo ifconfig eth0 192.168.10.222 netmask 255.255.255.0
sudo route add default
Runtime.getRuntime().exec("dhclient ....");
有线wlan,这里有线设备名称为eth0(有关有线和无线设备可以在目录/sys/class/net/目录下看到)
主要配置文件:
/etc/network/interfaces 这个文件是保存ip,netmask,gateway信息的(包括静态和动态),实时生效的
/etc/resolv.conf 这个文件是保存DNS服务器信息的,实时生效
/etc/hosts 、/etc/hostname 在基于debian的linux系统中,修改主机名称,需要修改这两个文件,必须重启才能生效
设置自动获取IP
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo dhclient eth0
执行完上述命令以后,查看/etc/network/interfaces :
# Used by ifup(8) and ifdown(8). See the interfaces(5) manpage or
# /usr/share/doc/ifupdown/examples for more information.
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
#iface eth0 inet static
查看/etc/resolv.conf :
nameserver 192.168.200.200
nameserver 192.168.200.240
修改主机名:
同时修改/etc/hosts 、/etc/hostname这两个文件即可
设置自定义IP
sudo ifconfig eth0 down
sudo ifconfig eth0 up
sudo ifconfig eth0 192.168.10.222 netmask 255.255.255.0
sudo route add default