一、查看网络适配器名称
root@svros:~ # ifconfig em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500 options=81009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,VLAN_HWFILTER> ether 00:0c:29:33:c5:90 inet 192.168.107.128 netmask 0xffffff00 broadcast 192.168.107.255 media: Ethernet autoselect (1000baseT <full-duplex>) status: active nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
二、配置DHCP
# sysrc ifconfig_em0="DHCP"
或者
# vi /etc/rc.conf hostname="svros.com" ifconfig_em0="DHCP" //设置动态获取ip local_unbound_enable="YES" sshd_enable="YES" moused_enable="YES" ntpdate_enable="YES" ntpd_enable="YES" powerd_enable="YES" dumpdev="AUTO"
三、配置静态IP
sysrc ifconfig_em0="inet 192.168.107.128/24" defaultrouter="192.168.107.2"
或者
#vi /etc/rc.conf hostname="server1.example.com" ifconfig_em0="inet 10.10.10.100 netmask 255.255.255.0" //设置ip地址和子网掩码 defaultrouter="10.10.10.1" //设置默认网关 dumpdev="AUTO"
四、配置DNS
# vi /etc/resolv.conf # nameserver 192.168.253.2 nameserver 114.114.114.114 nameserver 127.0.0.1 options edns0
五、重启网络
# service netif restart
# service routing restart
或者
# sh /etc/rc //刷新系统设置 # /etc/netstart //重启网络
六、测试网络连通性
# ping baidu.com