1. 首页 > IT综合教程 > 正文

it教程FG91-Windows网络配置与管理

1. 网络配置概述

Windows Server 2022的网络配置是系统管理的重要组成部分,包括IP地址、DNS、路由等配置。本文将详细介绍Windows Server 2022的网络配置与管理方法。更多学习教程www.fgedu.net.cn

# 查看网络适配器信息
PS C:\> Get-NetAdapter

Name InterfaceDescription ifIndex Status MacAddress LinkSpeed
—- ——————– ——- —— ———- ———
Ethernet Microsoft Hyper-V Network Adapter 2 Up 00-15-5D-00-01-02 10 Gbps
Loopback Pseudo-Interface 1 Software Loopback Interface 1 1 Up 00-00-00-00-00-00 10 Gbps

生产环境建议:网络配置前,建议先备份当前的网络配置,以便在配置出错时可以快速恢复。

2. IP地址配置

IP地址是网络设备在网络中的唯一标识,需要正确配置以确保设备能够在网络中通信。学习交流加群风哥微信: itpux-com

# 使用PowerShell配置静态IP地址
PS C:\> New-NetIPAddress -InterfaceAlias “Ethernet” -IPAddress “192.168.1.100” -PrefixLength 24 -DefaultGateway “192.168.1.1”

# 使用PowerShell配置动态IP地址(DHCP)
PS C:\> Set-NetIPInterface -InterfaceAlias “Ethernet” -Dhcp Enabled

# 查看IP地址配置
PS C:\> Get-NetIPAddress -InterfaceAlias “Ethernet”

IPAddress : 192.168.1.100
InterfaceIndex : 2
InterfaceAlias : Ethernet
AddressFamily : IPv4
Type : Unicast
PrefixLength : 24
PrefixOrigin : Manual
SuffixOrigin : Manual
AddressState : Preferred
ValidLifetime : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource : False
PolicyStore : ActiveStore

# 使用图形界面配置IP地址
# 步骤1:打开网络和共享中心
# 步骤2:点击”更改适配器设置”
# 步骤3:右键点击网络适配器,选择”属性”
# 步骤4:选择”Internet协议版本4 (TCP/IPv4)”,点击”属性”
# 步骤5:选择”使用下面的IP地址”,输入IP地址、子网掩码和默认网关
# 步骤6:点击”确定”保存配置
风哥提示:在生产环境中,建议使用静态IP地址配置,以确保服务的稳定性和可预测性。

3. DNS配置

DNS(域名系统)用于将域名解析为IP地址,是网络通信的重要组成部分。

# 使用PowerShell配置DNS服务器
PS C:\> Set-DnsClientServerAddress -InterfaceAlias “Ethernet” -ServerAddresses “8.8.8.8”, “8.8.4.4”

# 查看DNS配置
PS C:\> Get-DnsClientServerAddress -InterfaceAlias “Ethernet”

InterfaceAlias Interface Address ServerAddresses
Index Family
————– ——— ——- —————
Ethernet 2 IPv4 {8.8.8.8, 8.8.4.4}
Ethernet 2 IPv6 {2001:4860:4860::8888, 2001:4860:4860::8844}

# 测试DNS解析
PS C:\> Resolve-DnsName www.baidu.com

Name Type TTL Section IPAddress
—- —- — ——- ———-
www.baidu.com CNAME 5 Answer www.a.shifen.com
www.a.shifen.com A 5 Answer 110.242.68.3
www.a.shifen.com A 5 Answer 110.242.68.4

4. 路由配置

路由配置决定了网络数据包的传输路径,是网络通信的重要组成部分。学习交流加群风哥QQ113257174

# 查看路由表
PS C:\> Get-NetRoute

ifIndex DestinationPrefix NextHop RouteMetric ifMetric PolicyStore
——- —————– ——- ———– ——– ———–
2 0.0.0.0/0 192.168.1.1 256 20 ActiveStore
2 192.168.1.0/24 0.0.0.0 256 20 ActiveStore
1 127.0.0.0/8 0.0.0.0 256 50 ActiveStore
1 127.0.0.1/32 0.0.0.0 256 50 ActiveStore

# 添加静态路由
PS C:\> New-NetRoute -InterfaceAlias “Ethernet” -DestinationPrefix “192.168.2.0/24” -NextHop “192.168.1.254” -RouteMetric 10

# 删除静态路由
PS C:\> Remove-NetRoute -InterfaceAlias “Ethernet” -DestinationPrefix “192.168.2.0/24”

5. 防火墙配置

Windows防火墙用于保护系统免受网络攻击,需要正确配置以确保系统安全。

# 查看防火墙状态
PS C:\> Get-NetFirewallProfile | Select-Object Name, Enabled

Name Enabled
—- ——-
Domain True
Private True
Public True

# 启用防火墙
PS C:\> Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled True

# 禁用防火墙
PS C:\> Set-NetFirewallProfile -Profile Domain,Private,Public -Enabled False

# 查看已开放的端口
PS C:\> Get-NetFirewallRule | Where-Object {$_.Action -eq “Allow” -and $_.Enabled -eq “True”} | Select-Object DisplayName, LocalPort

DisplayName LocalPort
———– ———
Core Networking – DNS (UDP-In) 53
Core Networking – DHCP (UDP-In) 67
Core Networking – ICMPv4-In {8}
Remote Desktop – User Mode (TCP-In) 3389

# 开放端口
PS C:\> New-NetFirewallRule -DisplayName “HTTP” -Direction Inbound -LocalPort 80 -Protocol TCP -Action Allow

# 关闭端口
PS C:\> Remove-NetFirewallRule -DisplayName “HTTP”

生产环境建议:在生产环境中,建议只开放必要的端口,以减少系统暴露的攻击面。

6. 网络工具使用

Windows系统提供了丰富的网络工具,用于网络配置、监控和故障排查。更多学习教程公众号风哥教程itpux_com

# 测试网络连通性
PS C:\> Test-Connection -ComputerName 192.168.1.1 -Count 4

Source Destination IPV4Address IPV6Address Bytes Time(ms)
—— ———– ———– ———– —– ——–
fgedu 192.168.1.1 192.168.1.1 32 0
fgedu 192.168.1.1 192.168.1.1 32 0
fgedu 192.168.1.1 192.168.1.1 32 0
fgedu 192.168.1.1 192.168.1.1 32 0

# 跟踪路由
PS C:\> Test-NetConnection -ComputerName 8.8.8.8 -TraceRoute

ComputerName : 8.8.8.8
RemoteAddress : 8.8.8.8
InterfaceAlias : Ethernet
SourceAddress : 192.168.1.100
PingSucceeded : True
PingReplyDetails (RTT) : 15 ms
TraceRoute : 192.168.1.1
10.0.0.1
202.106.0.1
202.106.1.1
8.8.8.8

# 查看网络连接
PS C:\> netstat -ano

Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:22 0.0.0.0:0 LISTENING 1234
TCP 0.0.0.0:3389 0.0.0.0:0 LISTENING 5678
TCP 127.0.0.1:25 0.0.0.0:0 LISTENING 9012
UDP 0.0.0.0:68 *:* 3456
UDP [::]:546 *:* 3456

# 查看网络适配器详细信息
PS C:\> ipconfig /all

Windows IP Configuration

Host Name . . . . . . . . . . . . : fgedu
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Hybrid
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No

Ethernet adapter Ethernet:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Microsoft Hyper-V Network Adapter
Physical Address. . . . . . . . . : 00-15-5D-00-01-02
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
IPv4 Address. . . . . . . . . . . : 192.168.1.100(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1
DNS Servers . . . . . . . . . . . : 8.8.8.8
8.8.4.4
NetBIOS over Tcpip. . . . . . . . : Enabled

7. 网络监控

网络监控是确保网络正常运行的重要手段,需要定期检查网络状态和性能。

# 查看网络流量
PS C:\> Get-NetAdapterStatistics -InterfaceAlias “Ethernet”

Name ReceivedBytes ReceivedUnicastPackets ReceivedNonUnicastPackets ReceivedDiscardedPackets ReceivedErrors
—- ———— ——————— ———————– ———————- ————
Ethernet 123456789 123456 7890 0 0

# 查看网络连接状态
PS C:\> Get-NetTCPConnection | Where-Object {$_.State -eq “Established”} | Select-Object LocalAddress, LocalPort, RemoteAddress, RemotePort, State

LocalAddress LocalPort RemoteAddress RemotePort State
———— ——— ————- ———- —–
192.168.1.100 54321 192.168.1.200 3389 Established
192.168.1.100 12345 8.8.8.8 53 Established

# 使用性能监视器监控网络
# 步骤1:打开性能监视器
# 步骤2:添加计数器
# 步骤3:选择”Network Interface”类别
# 步骤4:选择需要监控的计数器,如”Bytes Total/sec”、”Packets Total/sec”等
# 步骤5:点击”添加”,然后点击”确定”
# 步骤6:查看监控数据
风哥提示:定期监控网络流量和连接状态,可以及时发现网络问题并采取措施解决。

8. 网络故障排查

网络故障排查是系统管理员的重要技能,需要掌握基本的排查方法和工具。

# 排查网络连接问题
# 1. 检查物理连接
# 2. 检查网络适配器状态
PS C:\> Get-NetAdapter | Select-Object Name, Status

# 3. 检查IP地址配置
PS C:\> ipconfig /all

# 4. 检查路由配置
PS C:\> Get-NetRoute

# 5. 检查DNS配置
PS C:\> Get-DnsClientServerAddress

# 6. 测试网络连通性
PS C:\> Test-Connection -ComputerName 192.168.1.1

# 7. 测试DNS解析
PS C:\> Resolve-DnsName www.baidu.com

# 8. 检查防火墙配置
PS C:\> Get-NetFirewallRule | Where-Object {$_.Action -eq “Allow” -and $_.Enabled -eq “True”}

# 排查网络性能问题
# 1. 检查网络延迟
PS C:\> Test-Connection -ComputerName 192.168.1.1 -Count 10

# 2. 检查网络带宽
# 使用iPerf3工具测试网络带宽
# 下载iPerf3工具并解压
# 在服务器端运行:iperf3 -s
# 在客户端运行:iperf3 -c 192.168.1.100

# 3. 检查网络丢包
PS C:\> Test-Connection -ComputerName 192.168.1.1 -Count 100 | Measure-Object -Property ResponseTime -Average

# 4. 检查网络接口利用率
# 使用性能监视器监控网络接口利用率

9. 网络服务配置

Windows Server 2022提供了多种网络服务,如DHCP、DNS、WINS等,需要正确配置以确保网络服务的正常运行。author:www.itpux.com

# 查看网络服务状态
PS C:\> Get-Service | Where-Object {$_.Name -like “*DHCP*” -or $_.Name -like “*DNS*” -or $_.Name -like “*WINS*”} | Select-Object Name, Status, DisplayName

Name Status DisplayName
—- —— ———–
DnsCache Running DNS Client
Dhcp Running DHCP Client
W32Time Running Windows Time

# 启动网络服务
PS C:\> Start-Service -Name “Dhcp”

# 停止网络服务
PS C:\> Stop-Service -Name “Dhcp”

# 设置服务自启动
PS C:\> Set-Service -Name “Dhcp” -StartupType Automatic

10. 最佳实践

网络配置和管理的最佳实践可以提高系统的可靠性和安全性。

生产环境建议:
– 使用静态IP地址配置,避免DHCP带来的IP地址变化
– 合理规划网络地址空间,避免IP地址冲突
– 配置合适的DNS服务器,确保域名解析正常
– 配置防火墙,只开放必要的端口
– 定期备份网络配置
– 定期监控网络状态和性能
– 建立网络故障应急预案

# 网络配置备份
# 备份网络适配器配置
PS C:\> Get-NetAdapter | Export-Clixml -Path “C:\Backup\NetworkAdapters.xml”

# 备份IP地址配置
PS C:\> Get-NetIPAddress | Export-Clixml -Path “C:\Backup\IPAddresses.xml”

# 备份DNS配置
PS C:\> Get-DnsClientServerAddress | Export-Clixml -Path “C:\Backup\DNSConfig.xml”

# 备份防火墙配置
PS C:\> Get-NetFirewallRule | Export-Clixml -Path “C:\Backup\FirewallRules.xml”

生产环境建议:网络配置变更前,建议先在测试环境验证,然后再在生产环境实施,以避免配置错误导致的网络中断。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息