MAC Address
Media Access Control Address
A unique identifier of a network interface. A 48-bit hardware address. Used in Ethernet and Wi-Fi.
Media Access Control Address
A unique identifier of a network interface. A 48-bit hardware address. Used in Ethernet and Wi-Fi.
A MAC address (Media Access Control Address) is a 48-bit (6-byte) unique identifier assigned to a network interface card (NIC). Also called a "physical address" or "hardware address," it is used to identify devices at the data link layer (OSI Layer 2), such as Ethernet or Wi-Fi. Example: it is written in the format 00:1A:2B:3C:4D:5E or 00-1A-2B-3C-4D-5E.
The structure of a MAC address is divided into two parts. The first 24 bits (3 bytes) are the OUI (Organizationally Unique Identifier), a unique number assigned to the manufacturer by the IEEE. For example, 00:1A:2B is assigned to Apple and 00:50:56 to VMware. The last 24 bits (3 bytes) are a serial number that the manufacturer assigns to each device. Thanks to this structure, every network device in the world theoretically has a unique MAC address.
ARP (Address Resolution Protocol) is a protocol that translates IP addresses into MAC addresses. When communicating within the same network, even if you know the destination's IP address, you need its MAC address to send an actual Ethernet frame. ARP broadcasts "Who has this IP address?", and the device that has it replies with its own MAC address. The result is stored in the ARP cache to avoid repeated lookups.
In modern network security, MAC address management is an important issue. MAC address filtering can allow only permitted devices to access the network, but because MAC spoofing (forgery) is possible, it is not sufficient as a standalone security measure. To protect privacy, modern operating systems such as iOS, Android, and Windows 10+ provide a feature that uses a random MAC address when connecting to Wi-Fi.
import uuid
import subprocess
import re
from getmac import get_mac_address # pip install getmac
# 로컬 장치 MAC 주소 조회
local_mac = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
print(f"로컬 MAC: {local_mac}") # 예: 00:1a:2b:3c:4d:5e
# getmac 라이브러리 사용 (권장)
mac = get_mac_address()
print(f"기본 인터페이스 MAC: {mac}")
# 특정 인터페이스 MAC 조회
eth_mac = get_mac_address(interface="eth0")
wifi_mac = get_mac_address(interface="wlan0")
# 원격 호스트 MAC 조회 (같은 서브넷)
remote_mac = get_mac_address(ip="192.168.1.1")
print(f"게이트웨이 MAC: {remote_mac}")
# MAC 주소 형식 변환
def format_mac(mac, delimiter=":"):
"""MAC 주소 형식 변환: 00:1A:2B → 00-1A-2B"""
clean = mac.replace(":", "").replace("-", "").upper()
return delimiter.join(clean[i:i+2] for i in range(0, 12, 2))
# OUI 파싱 (제조사 식별)
def get_oui(mac):
"""MAC 주소에서 OUI(제조사 식별자) 추출"""
clean = mac.replace(":", "").replace("-", "")[:6].upper()
# 실제로는 IEEE OUI 데이터베이스 조회 필요
oui_db = {"001A2B": "Apple", "005056": "VMware", "001C42": "Parallels"}
return oui_db.get(clean, "Unknown")
print(format_mac("00:1a:2b:3c:4d:5e", "-")) # 00-1A-2B-3C-4D-5E
# MAC 주소 조회 (Linux)
ip link show # 모든 인터페이스 MAC
ip link show eth0 # 특정 인터페이스
cat /sys/class/net/eth0/address # 직접 읽기
# MAC 주소 조회 (macOS)
ifconfig en0 | grep ether # Wi-Fi 인터페이스
networksetup -getmacaddress Wi-Fi
# MAC 주소 조회 (Windows)
ipconfig /all # 모든 인터페이스
getmac # MAC 주소만 출력
# ARP 테이블 조회 (IP ↔ MAC 매핑)
arp -a # 전체 ARP 캐시
arp -n 192.168.1.1 # 특정 IP의 MAC
ip neigh show # Linux 최신 명령어
# ARP 캐시 삭제
sudo ip neigh flush all # Linux
arp -d * # macOS
arp -d 192.168.1.1 # 특정 항목 삭제
# MAC 주소 임시 변경 (Linux)
sudo ip link set dev eth0 down
sudo ip link set dev eth0 address 00:11:22:33:44:55
sudo ip link set dev eth0 up
# MAC 주소 변경 (macOS)
sudo ifconfig en0 ether 00:11:22:33:44:55
# OUI 조회 (제조사 확인)
# IEEE OUI 데이터베이스: https://standards-oui.ieee.org/
curl -s "https://api.macvendors.com/00:1A:2B"
# 응답: Apple, Inc.
const os = require('os');
const { exec } = require('child_process');
// 모든 네트워크 인터페이스 MAC 주소 조회
function getAllMacAddresses() {
const interfaces = os.networkInterfaces();
const macs = {};
for (const [name, addrs] of Object.entries(interfaces)) {
for (const addr of addrs) {
if (addr.mac && addr.mac !== '00:00:00:00:00:00') {
macs[name] = addr.mac;
break;
}
}
}
return macs;
}
console.log(getAllMacAddresses());
// { eth0: '00:1a:2b:3c:4d:5e', wlan0: '00:1a:2b:3c:4d:5f' }
// 기본 인터페이스 MAC 주소
function getDefaultMac() {
const interfaces = os.networkInterfaces();
for (const addrs of Object.values(interfaces)) {
for (const addr of addrs) {
if (!addr.internal && addr.family === 'IPv4' && addr.mac) {
return addr.mac;
}
}
}
return null;
}
// MAC 주소 유효성 검증
function isValidMac(mac) {
const regex = /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/;
return regex.test(mac);
}
console.log(isValidMac('00:1A:2B:3C:4D:5E')); // true
console.log(isValidMac('001A2B3C4D5E')); // false
// ARP 테이블 조회 (Linux/macOS)
exec('arp -a', (error, stdout) => {
if (error) return console.error(error);
const entries = stdout.split('\n')
.filter(line => line.includes('at'))
.map(line => {
const match = line.match(/\((\d+\.\d+\.\d+\.\d+)\).*at\s+([0-9a-f:]+)/i);
return match ? { ip: match[1], mac: match[2] } : null;
})
.filter(Boolean);
console.log('ARP 테이블:', entries);
});
"A wrong MAC address is left in the ARP cache, so packets are going to the wrong device. Clear the cache with arp -d and check again. If the problem keeps occurring, you should also check for the possibility of an ARP spoofing attack."
"I don't recommend controlling network access with MAC address filtering alone. MAC spoofing can be done in five minutes. Use it together with 802.1X authentication, or adopt a NAC solution. At the very least, enable Dynamic ARP Inspection (DAI)."
"A MAC address is a 48-bit physical address; the first 24 bits, the OUI, identify the manufacturer, and the last 24 bits are the device's unique number. The ARP protocol maps IP to MAC, and it is essential for communication within the same subnet. However, a MAC is valid only at L2 and changes when it passes through a router."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
MAC addresses can be easily forged (spoofed). If an attacker sniffs a permitted MAC address and sets it on their own device, they bypass the filter. Be sure to use it together with 802.1X, WPA3-Enterprise, and similar measures.
A MAC address is valid only on the local network (L2). When traffic passes through a router, the source MAC is replaced with the router's MAC. In internet communication, a remote server cannot know your MAC address.
An attacker can intercept traffic by sending fake ARP replies. Enable Dynamic ARP Inspection (DAI) on the switch, and configure static ARP entries for critical servers.
Use 802.1X port authentication together with MAC filtering. Limit MAC learning with Port Security on the switch. Prevent ARP spoofing with DAI and DHCP Snooping. For mobile devices, using the random MAC feature is recommended.