修改本地DNS地址为对应的ip地址

[root@localhost named]# cat /etc/sysconfig/network-scripts/ifcfg-eno16777736 
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=5ea81673-204d-4561-8edc-5c186434c544
ONBOOT=yes
DNS1=192.168.190.20
IPADDR0=192.168.190.20
PREFIX0=24
GATEWAY0=192.168.190.1
HWADDR=00:0C:29:7C:99:06
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
[root@localhost named]#

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用C#中的System.Net.NetworkInformation命名空间中的类来修改IP、网关和DNS。首先,需要获取当前网络接口的配置信息,然后可以使用NetworkInterface类来修改配置信息。 以下是一个基本的示例代码: ```csharp using System.Net; using System.Net.NetworkInformation; public void ModifyNetworkConfiguration(string ipAddress, string subnetMask, string gateway, string dns) { NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { if (ni.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 || ni.NetworkInterfaceType == NetworkInterfaceType.Ethernet) { IPInterfaceProperties ipProps = ni.GetIPProperties(); UnicastIPAddressInformationCollection unicastAddresses = ipProps.UnicastAddresses; foreach (UnicastIPAddressInformation address in unicastAddresses) { if (address.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { if (ipAddress != null) { ipProps.UnicastAddresses.Clear(); ipProps.UnicastAddresses.Add(new UnicastIPAddressInformation(IPAddress.Parse(ipAddress), IPAddress.Parse(subnetMask))); } if (gateway != null) { ipProps.GatewayAddresses.Clear(); ipProps.GatewayAddresses.Add(new GatewayIPAddressInformation(IPAddress.Parse(gateway))); } if (dns != null) { ipProps.DnsAddresses.Clear(); ipProps.DnsAddresses.Add(IPAddress.Parse(dns)); } ni.SetIPProperties(ipProps); } } } } } ``` 在上面的代码中,我们首先获取所有网络接口。然后,我们循环遍历每个接口,找到第一个IPv4地址,然后根据传入的参数修改IP地址、子网掩码、网关和DNS地址。最后,我们调用SetIPProperties方法来应用新的配置。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值