TranslateProject/published/201404/How to spoof the MAC address of a network interface on Linux.md
wxy 97bd3352b5 renamed: 10 Useful Random Linux Interview Questions and Answers_t.md -> 201404/10 Useful Random Linux Interview Questions and Answers_t.md
renamed:    10 ssh options for a Secure shell for Safe Data Communication.md -> 201404/10 ssh options for a Secure shell for Safe Data Communication.md
	renamed:    20 Funny Commands of Linux or Linux is Fun in Terminal.md -> 201404/20 Funny Commands of Linux or Linux is Fun in Terminal.md
	renamed:    2048 Now Available For Offline Play In Ubuntu.md -> 201404/2048 Now Available For Offline Play In Ubuntu.md
	renamed:    "5 Command Line Tools for Downloading Files\357\274\217Torrents and Browsing Websites.md" -> "201404/5 Command Line Tools for Downloading Files\357\274\217Torrents and Browsing Websites.md"
	renamed:    5 Linux Distributions that Deserve more Love.md -> 201404/5 Linux Distributions that Deserve more Love.md
	renamed:    A Beginners Guide for XP Users to Switch to Linux.md -> 201404/A Beginners Guide for XP Users to Switch to Linux.md
	renamed:    Beautiful Zukitwo Theme Is the First One for GNOME 3.12.md -> 201404/Beautiful Zukitwo Theme Is the First One for GNOME 3.12.md
	renamed:    Because You Can--Windows 8 GTK Theme For Linux.md -> 201404/Because You Can--Windows 8 GTK Theme For Linux.md
	renamed:    Collectl is a powerful tool to monitor system resources on Linux.md -> 201404/Collectl is a powerful tool to monitor system resources on Linux.md
	renamed:    "Daily Ubuntu Tips \342\200\223 Fix Black Screen In Ubuntu Guest With VirtualBox Screen Capture.md" -> "201404/Daily Ubuntu Tips \342\200\223 Fix Black Screen In Ubuntu Guest With VirtualBox Screen Capture.md"
	renamed:    "Daily Ubuntu Tips \342\200\223 HPLIP 3.14.3 Released \342\200\223 Upgrade In Ubuntu.md" -> "201404/Daily Ubuntu Tips \342\200\223 HPLIP 3.14.3 Released \342\200\223 Upgrade In Ubuntu.md"
	renamed:    Easily Switch Audio Sources With Sound Switcher Indicator In Ubuntu.md -> 201404/Easily Switch Audio Sources With Sound Switcher Indicator In Ubuntu.md
	renamed:    GitHub's New Atom Text Editor Is Open Source, Sort Of, Though Not Really.md -> 201404/GitHub's New Atom Text Editor Is Open Source, Sort Of, Though Not Really.md
	renamed:    Here Are Top 20 Linux Tutorials!.md -> 201404/Here Are Top 20 Linux Tutorials!.md
	renamed:    How To Find IP Conflicts In Linux.md -> 201404/How To Find IP Conflicts In Linux.md
	renamed:    How to Wipe Free Disk Space in Linux.md -> 201404/How to Wipe Free Disk Space in Linux.md
	renamed:    How to enable 32-bit support for 64-bit Ubuntu 13.10 or greater.md -> 201404/How to enable 32-bit support for 64-bit Ubuntu 13.10 or greater.md
	renamed:    How to set up RainLoop webmail in Ubuntu server.md -> 201404/How to set up RainLoop webmail in Ubuntu server.md
	renamed:    How to spoof the MAC address of a network interface on Linux.md -> 201404/How to spoof the MAC address of a network interface on Linux.md
	renamed:    Interesting facts about Raspberry Pi.md -> 201404/Interesting facts about Raspberry Pi.md
	renamed:    Linux 3.15 Will Dramatically Reduce Suspend And Resume Times!.md -> 201404/Linux 3.15 Will Dramatically Reduce Suspend And Resume Times!.md
	renamed:    Linux Basics--Analyze Disk Usage In Ubuntu Linux.md -> 201404/Linux Basics--Analyze Disk Usage In Ubuntu Linux.md
	renamed:    Linux Commands Cheat Sheet in Black & White.md -> 201404/Linux Commands Cheat Sheet in Black & White.md
	renamed:    Linux Kernel News - January and February 2014.md -> 201404/Linux Kernel News - January and February 2014.md
	renamed:    Linux and Unix nload App - Monitor Network Traffic and Bandwidth Usage In Real Time.md -> 201404/Linux and Unix nload App - Monitor Network Traffic and Bandwidth Usage In Real Time.md
	renamed:    Meet uGet, an Amazing Download Manager for Linux.md -> 201404/Meet uGet, an Amazing Download Manager for Linux.md
	renamed:    Moving a city to Linux requires political backing, says Munich project leader.md -> 201404/Moving a city to Linux requires political backing, says Munich project leader.md
	renamed:    Open Source Isn't Just For Developers Anymore.md -> 201404/Open Source Isn't Just For Developers Anymore.md
	renamed:    Play the Best Linux Puzzle Games.md -> 201404/Play the Best Linux Puzzle Games.md
	renamed:    Red Hat Updates Open Source Software Development Tools.md -> 201404/Red Hat Updates Open Source Software Development Tools.md
	renamed:    Ubuntu Touch Email Client Mockup Design Looks Fantastic.md -> 201404/Ubuntu Touch Email Client Mockup Design Looks Fantastic.md
	renamed:    Ultimate Edition 3.9 Linux Distro Is a Complete Mess.md -> 201404/Ultimate Edition 3.9 Linux Distro Is a Complete Mess.md
	renamed:    What if Linus Torvalds Would Have Accepted Job Proposal of Steve Jobs.md -> 201404/What if Linus Torvalds Would Have Accepted Job Proposal of Steve Jobs.md
	renamed:    What is good video editing software on Linux.md -> 201404/What is good video editing software on Linux.md
	renamed:    Windows 7 & 8 Complete Transformation Pack Out for Ubuntu, Debian 8, and Arch Linux.md -> 201404/Windows 7 & 8 Complete Transformation Pack Out for Ubuntu, Debian 8, and Arch Linux.md
	renamed:    nSnake--Play The Classic Snake Game In Linux Terminal.md -> 201404/nSnake--Play The Classic Snake Game In Linux Terminal.md
2014-05-01 06:53:52 +08:00

5.5 KiB
Raw Blame History

Linux 上的 MAC 地址欺骗

网卡生产商在每一张网卡NIC在出厂时都会在上面刻上一个48位的全球唯一标识符GUID例如08:4f:b5:05:56:a0这串 GUID 就是网卡的 MAC 地址用于确定一张网卡的身份。MAC 地址的高24位叫 OUI(Organizationally Unique Identifier 组织唯一标示符),是为网卡设置 MAC 地址的组织的标识符,这样一来,不同组织设置的 MAC 地址就不会冲突了。译注实际生产中并不是每个网络设备都有不同的MAC地址有时候地址空间不足生产商会给发往不同地区国家的产品中用相同的地址空间。

虽然 MAC 地址由厂商指定但用户可以改变它这就是传说中的“MAC 地址欺骗”。本文将向大家展示如何在 Linux 上玩 MAC 地址欺骗

为什么要玩 MAC 地址欺骗?

想要理由?这里就给几个比较有技术含量的理由。 一些网络供应商会通过绑定你家路由器上的 MAC 地址来验证你的身份,这个时候如果你的路由器坏了,你怎么办?你可以暂时把你的电脑的 MAC 地址改成你家路由器的 MAC 地址,让你的 ISP 重新将你连入外网。(译注:有这种事情么?)

很多 DHCP 服务器会依赖 MAC 地址来分配 IP 地址。如果你想换一个分配给你的 IP 地址,你可以改改你的 MAC 地址。这样一来,你不必等着 DHCP 服务器给你重新分一个 IP 地址,而是马上就能得到一个新的。

除了技术原因外,这里也有一些比较正当的理由来说明你为什么需要改变你的 MAC 地址:为了隐私、为了安全,你要把你真正的 MAC 地址隐藏起来。不像处在 ISO 模型第三层的 IP 地址会经常变来变去,你的 MAC 地址可不会改变。在你说我多疑之前,请确定你知道你的隐私到底是什么东西。有一个入侵手段叫 piggybacking,黑客会在公共 WiFi 网络下伪装成你的 MAC 地址,并且在你不在场的时候伪装成你的身份进行黑客活动。

怎么临时性地改变 MAC 地址?

你可以在 Linux 运行的时候改变 MAC 地址。需要注意的是当 MAC 地址转换的那一会时间,你的网络会掉线。当电脑重启时 MAC 地址又会变回原来的。下面介绍几种方法来改变你的 MAC 地址。

方法一iproute2

$ sudo ip link set dev eth0 down
$ sudo ip link set dev eth0 address 00:00:00:00:00:01
$ sudo ip link set dev eth0 up 

方法二macchanger

macchanger 这个命令可以让你把 MAC 地址改成不同生产厂商的序列号。

在 DebianUbuntu 或 Linux Mint 下安装 macchanger

$ sudo apt-get install macchanger 

在 Fedora 下安装 macchanger

$ sudo yum install macchanger 

在 CentOS 或 RHEL 下安装 macchanger

$ wget http://ftp.club.cc.cmu.edu/pub/gnu/macchanger/macchanger-1.6.0.tar.gz
$ tar xvfvz macchanger-1.6.0.tar.gz
$ cd macchanger-1.6.0 
$ ./configure
$ make
$ sudo make install 

下面给出一些 macchanger 的高级使用例子。使用 macchanger 你不必再手动禁用、启用你的网卡。

仅仅改变 MAC 地址:

$ sudo macchanger --mac=00:00:00:00:00:01 eth0 

在保证 OUI 一致的情况下为 MAC 设置一个随机地址:

$ sudo macchanger -e eth0 

为 MAC 设置一个完全随机的地址:

$ sudo macchanger -r eth0 

获取所有网卡的 MAC 地址,然后只列出指定的厂商(比如 Juniper:

$ macchanger -l | grep -i juniper 

显示一块网卡原来的 MAC 地址和伪装的 MAC 地址:

$ macchanger -s eth0 
Current MAC:   56:95:ac:ee:6e:77 (unknown)
Permanent MAC: 00:0c:29:97:68:02 (Vmware, Inc.)

如何永久性地改变 MAC 地址?

如果你想在系统重启后还保持伪装 MAC 地址,你需要编辑配置文件。比如你想改变 eth0 的 MAC 地址,按以下方法搞起:

在 FedoraCentOS 或 RHEL 下:

$ sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
MACADDR=00:00:00:00:00:01

或者你可以建一个开机启动的脚本放在 /etc/NetworkManager/dispatcher.d 目录下,前提是你使用 Network Manager 管理你的网络。这里假设你已经装了 macchanger脚本内容如下

$ sudo vi /etc/NetworkManager/dispatcher.d/000-changemac 
#!/bin/bash

case "$2" in
    up)
        macchanger --mac=00:00:00:00:00:01 "$1"
        ;;
esac
$ sudo chmod 755 /etc/NetworkManager/dispatcher.d/000-changemac 

在 DebianUbuntu 或 Linux Mint 下:

新建一个开机启动脚本,放在 /etc/network/if-up.d/ 目录下:

$ sudo vi /etc/network/if-up.d/changemac 
#!/bin/sh

if [ "$IFACE" = eth0 ]; then
  ip link set dev "$IFACE" address 00:00:00:00:00:01
fi
$ sudo chmod 755 /etc/network/if-up.d/changemac 

via: http://xmodulo.com/2014/02/spoof-mac-address-network-interface-linux.html

译者:bazz2 校对:wxy

本文由 LCTT 原创翻译,Linux中国 荣誉推出