Files
wiki/ip-renew
2024-08-21 01:42:59 -04:00
..
2024-08-21 01:42:59 -04:00

WSL2에서 Windwos IP 변경하기

  • 아래의 방법으로 원하는 LAN카드의 MAC주소를 변경할 수 있다.

  • MAC주소가 변경되면 ISP 모뎀에서 새로운 기기로 인식하고 새로운 IP를 할당한다.

  • Powershell:

    # 현재 네트워크 어댑터 목록 확인
    Get-NetAdapter
    
    # MAC 주소 변경 (어댑터 이름과 원하는 MAC 주소 지정)
    Set-NetAdapter -Name "이더넷" -MacAddress "00-11-22-33-44-55"
    
    # 랜덤 MAC 주소 생성 및 설정
    $randomMac = (0..5 | ForEach-Object { "{0:X2}" -f (Get-Random -Minimum 0 -Maximum 255) }) -join '-'
    Set-NetAdapter -Name "이더넷" -MacAddress $randomMac
    

WSL2에서 Windows SSH 접속하기

WSL2의 명령어로 IP를 변경하기 위해 WSL2 -> Windows SSH 연결을 수립한다.

  • Powershell (관리자로 실행):
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
    Start-Service sshd
    Set-Service -Name sshd -StartupType 'Automatic'
    if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
        Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
        New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
    } else {
        Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
    }
    
    (Get-Content -Path "C:\ProgramData\ssh\sshd_config") | 
        ForEach-Object {$_ -replace "^#PubkeyAuthentication yes", "PubkeyAuthentication yes"} | 
        Set-Content -Path "C:\ProgramData\ssh\sshd_config"
    
    Restart-Service sshd

Debian에서 바라보는 Windows의 IP는 다음과 같이 얻을 수 있다.

  • Debian bash:
    ip route | grep default | awk '{print $3}'
    # 172.17.112.1
    

ssh 계정에 접속받기 위해서는 그 윈도우 계정에 암호가 설정되어 있어야 한다.

  • Debian bash:
    cat ~/.ssh/id_rsa.pub >> /mnt/c/Users/<YourUsername>/.ssh/authorized_keys
    ssh w@$(ip route | grep default | awk '{print $3}')