การเขียน Script Batch File Set IP

ตัวอย่างการเขียน Script Set IP Static

เปิดโปรแกรม Notepad แล้วพิมพ์คำสั่ง ดังนี้

netsh int ipv4 set address name="Ethernet" source=static address=192.168.17.107 mask=255.255.255.0 gateway=192.168.17.1
netsh interface ipv4 add dns "Ethernet" address=8.8.8.8 index=1
netsh interface ipv4 add dns "Ethernet" address=8.8.4.4 index=2


อธิบาย ดังนี้
netsh int ipv4 set address name="Ethernet"  > คือชื่อของ Ethernet Card
source=static address=192.168.17.107  > คือการกำหนด IP Address เป็น 192.168.17.107
mask=255.255.255.0  > คือ กำหนด net mask เป็น 255.255.255.0
gateway=192.168.17.1  > คือ กำหนด Gateway เป็น 192.168.17.1

netsh interface ipv4 add dns "Ethernet" address=8.8.8.8 index=1  >  คือ ตั้งค่า DNS ตัวที่ 1
netsh interface ipv4 add dns "Ethernet" address=8.8.4.4 index=2  >  คือ ตั้งค่า DNS ตัวที่ 2

* DNS ด้านบนผมใช้ ของ Google นะครับ
เมือพิมคำสั่งด้านบนแล้ว ให้ Save เป็นไฟล์นามสกุล bat เช่น  Static IP.bat  


ตัวอย่างการเขียน Script Set IP DHCP

netsh interface ip set address "Ethernet" dhcp

netsh interface ip set dns "Ethernet" dhcp

เมือพิมคำสั่งด้านบนแล้ว ให้ Save เป็นไฟล์นามสกุล bat เช่น  DHCP IP.bat  

วิธีการใช้งานคือให้คลิกขวาที่ไฟล์ แล้วเลือก Run As Admin... แล้วลองดูว่าไอพีของเครื่องเปลี่ยนหรือไม่น่ะครับ ถ้ายังไม่เปลี่ยนต้องลองดูที่ชื่อของ Ethernet Card ว่าตรงตามเครื่องของเราหรือป่าวน่ะครับ

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

วิธีการเช็ค Windows แท้ และดู Keys Windows 10/11

Install and configure Zabbix Debian 12 and apache2

Batch file copy folder to another folder by date (ตั้งค่า copy folder เพื่อ backup โดยการ copy อัตโนมัติไปเก็บใน Folder ที่สร้างตามวันที่ปัจจุบัน)