search
HomeOperation and MaintenanceMac OSMacOS configuration network tutorial

MacOS configuration network tutorial

May 12, 2020 am 11:02 AM
macos

1. IP address configuration

Manually specify the IP

The following 3 commands can complete the IP address Configuration:

- ifconfig interface [address_family] [address [netmask]]

- ipconfig set interface-name (MANUAL | INFORM) ip-address subnet-mask

- networksetup -setmanual

Example of manually specifying IP:

macbook$ sudo ifconfig en0 inet 192.168.1.10 netmask 255.255.255.0
macbook$ sudo ipconfig set en0 MANUAL 192.168.1.10 255.255.255.0
macbook$ sudo networksetup -setmanual Wi-Fi 192.168.1.10 255.255.255.0 192.168.1.1

Note: ifconfig and ipconfig both specify networks port device name, while networksetup requires the use of the alias set by MacOS for the network port (so-called "network service") to specify the network port.

Use DHCP to configure IP

You can use the following 2 commands to re-obtain the DHCP configuration:

- ipconfig set interface-name ( DHCP | BOOTP)

- networksetup -setdhcp

Example of using DHCP to dynamically obtain an IP address:

macbook$ ipconfig set en0 DHCP
macbook$ networksetup -setdhcp Wi-Fi

Note: ifconfig and ipconfig are both specified The name of the network port device, and networksetup requires the use of the alias set by MacOS for the network port (so-called "network service") to specify the network port.

Configuring the default gateway

You can use the following command to configure the default gateway:

- networksetup -setmanual

- route [add | change ] default

- route [add | change ] -net 0.0.0.0

Default gateway configuration example:

macbook$ sudo networksetup -setmanual Wi-Fi 192.168.1.10 255.255.255.0 192.168.1.1

The following two commands are equivalent:

macbook$ sudo route add default 192.168.1.1
macbook$ sudo route add -net 0.0.0.0 192.168.1.1

If a default route already exists, you may need to delete the existing default route first, and then add the default route Route:

macbook$ sudo route delete default
macbook$ sudo route add default 192.168.1.1

Or you can replace the existing default route:

macbook$ sudo route change default 192.168.1.1

Add static route

You can add a route using the following command:

macbook$ sudo route [-n] [add | delete | change] [-net | -host] [-ifscope boundif] destination gateway [netmask]

First check the current routing table:

macbook$ netstat -nr
Routing tables
Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           21        5     en0
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              1     1699     lo0
169.254            link#4             UCS             0        0     en0
169.254            link#6             UCSI            1        0     en6
169.254.89.143/32  link#6             UCS             0        0     en6
192.168.1          link#4             UCS             1        0     en0
192.168.1.1/32     link#4             UCS             1        0     en0
192.168.1.1        f4:ec:38:1e:ea:52  UHLWIir        19      224     en0    887
192.168.1.101/32   link#4             UCS             1        0     en0
192.168.1.101      48:d7:5:cb:7d:bd   UHLWIi          1        4     lo0
192.168.1.104      7c:b2:32:70:33:5c  UHLWI           0        2     en0   1053
224.0.0/4          link#4             UmCS            2        0     en0
224.0.0/4          link#6             UmCSI           0        0     en6
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0        3     en0
255.255.255.255/32 link#4             UCS             0        0     en0
255.255.255.255/32 link#6             UCSI            0        0     en6
Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun1                    UGcI          utun1
::1                                     ::1                             UHL             lo0
fdf7:a4c1:cda:e04f::/64                 fe80::f4d3:8e83:6ac7:4c70%utun0 Uc            utun0
fdf7:a4c1:cda:e04f:f4d3:8e83:6ac7:4c70  link#10                         UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::ca3:96a0:7113:b973%en0            48:d7:5:cb:7d:bd                UHLI            lo0
fe80::%en6/64                           link#6                          UCI             en6
fe80::c02:7c0f:52a1:d528%en6            ff:fa:0:0:78:86                 UHLI            lo0
fe80::%awdl0/64                         link#8                          UCI           awdl0
fe80::e00e:6dff:fef9:e630%awdl0         e2:e:6d:f9:e6:30                UHLI            lo0
fe80::%utun0/64                         fe80::f4d3:8e83:6ac7:4c70%utun0 UcI           utun0
fe80::f4d3:8e83:6ac7:4c70%utun0         link#10                         UHLI            lo0
fe80::%utun1/64                         fe80::593a:c424:495:3b05%utun1  UcI           utun1
fe80::593a:c424:495:3b05%utun1          link#11                         UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff01::%en6/32                           link#6                          UmCI            en6
ff01::%awdl0/32                         link#8                          UmCI          awdl0
ff01::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff01::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
ff02::%en6/32                           link#6                          UmCI            en6
ff02::%awdl0/32                         link#8                          UmCI          awdl0
ff02::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff02::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1

Method 1: Add route:

macbook$ sudo route add -net 10.1.1.1/32 192.168.1.1
Password:
add net 10.1.1.1: gateway 192.168.1.1

Check the current routing table:

macbook$ netstat -nr
Routing tables
Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           23        5     en0
10.1.1.1/32        192.168.1.1        UGSc            0        0     en0
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              1     1699     lo0
169.254            link#4             UCS             0        0     en0
169.254            link#6             UCSI            1        0     en6
169.254.89.143/32  link#6             UCS             0        0     en6
192.168.1          link#4             UCS             1        0     en0
192.168.1.1/32     link#4             UCS             1        0     en0
192.168.1.1        f4:ec:38:1e:ea:52  UHLWIir        22      210     en0   1000
192.168.1.101/32   link#4             UCS             1        0     en0
192.168.1.101      48:d7:5:cb:7d:bd   UHLWI           0        4     lo0
192.168.1.104      7c:b2:32:70:33:5c  UHLWIi          1        2     en0   1166
224.0.0/4          link#4             UmCS            2        0     en0
224.0.0/4          link#6             UmCSI           0        0     en6
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0        3     en0
255.255.255.255/32 link#4             UCS             0        0     en0
255.255.255.255/32 link#6             UCSI            0        0     en6
Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun1                    UGcI          utun1
::1                                     ::1                             UHL             lo0
fdf7:a4c1:cda:e04f::/64                 fe80::f4d3:8e83:6ac7:4c70%utun0 Uc            utun0
fdf7:a4c1:cda:e04f:f4d3:8e83:6ac7:4c70  link#10                         UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::ca3:96a0:7113:b973%en0            48:d7:5:cb:7d:bd                UHLI            lo0
fe80::%en6/64                           link#6                          UCI             en6
fe80::c02:7c0f:52a1:d528%en6            ff:fa:0:0:78:86                 UHLI            lo0
fe80::%awdl0/64                         link#8                          UCI           awdl0
fe80::e00e:6dff:fef9:e630%awdl0         e2:e:6d:f9:e6:30                UHLI            lo0
fe80::%utun0/64                         fe80::f4d3:8e83:6ac7:4c70%utun0 UcI           utun0
fe80::f4d3:8e83:6ac7:4c70%utun0         link#10                         UHLI            lo0
fe80::%utun1/64                         fe80::593a:c424:495:3b05%utun1  UcI           utun1
fe80::593a:c424:495:3b05%utun1          link#11                         UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff01::%en6/32                           link#6                          UmCI            en6
ff01::%awdl0/32                         link#8                          UmCI          awdl0
ff01::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff01::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
ff02::%en6/32                           link#6                          UmCI            en6
ff02::%awdl0/32                         link#8                          UmCI          awdl0
ff02::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff02::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1

Method 2: Add route:

macbook$ sudo route add -net 10.1.1.2 -netmask 255.255.255.255 192.168.1.1

add net 10.1.1.2: gateway 192.168.1.1

View routing table:

macbook$ netstat -nr
Routing tables
Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.1.1        UGSc           21        5     en0
10.1.1.1/32        192.168.1.1        UGSc            0        0     en0
10.1.1.2/32        192.168.1.1        UGSc            0        0     en0
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              1     1699     lo0
169.254            link#4             UCS             0        0     en0
169.254            link#6             UCSI            1        0     en6
169.254.89.143/32  link#6             UCS             0        0     en6
192.168.1          link#4             UCS             2        0     en0
192.168.1.1/32     link#4             UCS             1        0     en0
192.168.1.1        f4:ec:38:1e:ea:52  UHLWIir        21      224     en0    962
192.168.1.101/32   link#4             UCS             1        0     en0
192.168.1.101      48:d7:5:cb:7d:bd   UHLWI           0        4     lo0
192.168.1.104      7c:b2:32:70:33:5c  UHLWI           0        2     en0   1128
224.0.0/4          link#4             UmCS            2        0     en0
224.0.0/4          link#6             UmCSI           0        0     en6
224.0.0.251        1:0:5e:0:0:fb      UHmLWI          0        0     en0
239.255.255.250    1:0:5e:7f:ff:fa    UHmLWI          0        3     en0
255.255.255.255/32 link#4             UCS             0        0     en0
255.255.255.255/32 link#6             UCSI            0        0     en6
Internet6:
Destination                             Gateway                         Flags         Netif Expire
default                                 fe80::%utun1                    UGcI          utun1
::1                                     ::1                             UHL             lo0
fdf7:a4c1:cda:e04f::/64                 fe80::f4d3:8e83:6ac7:4c70%utun0 Uc            utun0
fdf7:a4c1:cda:e04f:f4d3:8e83:6ac7:4c70  link#10                         UHL             lo0
fe80::%lo0/64                           fe80::1%lo0                     UcI             lo0
fe80::1%lo0                             link#1                          UHLI            lo0
fe80::%en0/64                           link#4                          UCI             en0
fe80::ca3:96a0:7113:b973%en0            48:d7:5:cb:7d:bd                UHLI            lo0
fe80::%en6/64                           link#6                          UCI             en6
fe80::c02:7c0f:52a1:d528%en6            ff:fa:0:0:78:86                 UHLI            lo0
fe80::%awdl0/64                         link#8                          UCI           awdl0
fe80::e00e:6dff:fef9:e630%awdl0         e2:e:6d:f9:e6:30                UHLI            lo0
fe80::%utun0/64                         fe80::f4d3:8e83:6ac7:4c70%utun0 UcI           utun0
fe80::f4d3:8e83:6ac7:4c70%utun0         link#10                         UHLI            lo0
fe80::%utun1/64                         fe80::593a:c424:495:3b05%utun1  UcI           utun1
fe80::593a:c424:495:3b05%utun1          link#11                         UHLI            lo0
ff01::%lo0/32                           ::1                             UmCI            lo0
ff01::%en0/32                           link#4                          UmCI            en0
ff01::%en6/32                           link#6                          UmCI            en6
ff01::%awdl0/32                         link#8                          UmCI          awdl0
ff01::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff01::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1
ff02::%lo0/32                           ::1                             UmCI            lo0
ff02::%en0/32                           link#4                          UmCI            en0
ff02::%en6/32                           link#6                          UmCI            en6
ff02::%awdl0/32                         link#8                          UmCI          awdl0
ff02::%utun0/32                         fe80::f4d3:8e83:6ac7:4c70%utun0 UmCI          utun0
ff02::%utun1/32                         fe80::593a:c424:495:3b05%utun1  UmCI          utun1

2. Set DNS

Specify DNS server

Configuration command:

macbook$ networksetup -setdnsservers <networkservice> <dns1> [dns2] [...]

Example:

macbook$ sudo networksetup -setdnsservers Wi-Fi 114.114.114.114 114.114.114.115

When the DNS address parameter is not specified, clear the configured DNS server:

macbook$ sudo networksetup -setdnsservers Wi-Fi

View the currently configured DNS server

Method 1: View the manually specified DNS server address

Command:

macbook$ networksetup -getdnsservers

Note: This command can only view the manually specified one DNS server address, the DNS address obtained by DHCP cannot be viewed!

Example:

macbook$ sudo networksetup -getdnsservers Wi-Fi

Method 2: View the DNS address configured by DHCP

Command:

macbook$ ipconfig getpacket interface-name

This command is used to view the DNS address configured by DHCP The relevant network configuration information obtained also includes DNS configuration information!

Example:

macbook$ sudo ipconfig getpacket en0
Password:
op = BOOTREPLY
htype = 1
flags = 0
hlen = 6
hops = 0
xid = 0x1da0b2e6
secs = 0
ciaddr = 0.0.0.0
yiaddr = 192.168.1.101
siaddr = 0.0.0.0
giaddr = 0.0.0.0
chaddr = 48:d7:5:cb:7d:bd
sname = 
file = 
options:
Options count is 7
dhcp_message_type (uint8): ACK 0x5
server_identifier (ip): 192.168.1.1
lease_time (uint32): 0xffffffff
subnet_mask (ip): 255.255.255.0
router (ip_mult): {192.168.1.1}
domain_name_server (ip_mult): {114.114.114.114, 114.114.115.115}
end (none):

3. Clear DNS cache

OS X 10.9 (Mavericks):

macbook$ dscacheutil -flushcache; sudo killall -HUP mDNSResponder

OS X 10.10 ( Yosemite):

macbook$ sudo discoveryutil udnsflushcaches

Versions 10.10.4 :

macbook$ sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder

OS X 10.11 (El Capitan) and OS X 10.12 (Sierra):

macbook$ sudo killall -HUP mDNSResponder

OS X 10.12.4:

macbook$ sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache;

Recommended tutorial: "MacOS Tutorial"

The above is the detailed content of MacOS configuration network tutorial. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:CSDN. If there is any infringement, please contact admin@php.cn delete
Understanding macOS: A Beginner's GuideUnderstanding macOS: A Beginner's GuideApr 22, 2025 am 12:11 AM

The basic operations of macOS include starting applications, managing files, and using system settings. 1. Start the application: Use the Terminal command "open-aSafari" to start the Safari browser. 2. Manage files: browse and organize files through Finder. 3. Use system settings: understand the functions of Dock and Launchpad to improve operational efficiency. Through these basic operations, you can quickly master how to use macOS.

macOS and Linux: Understanding the Key DifferencesmacOS and Linux: Understanding the Key DifferencesApr 21, 2025 am 12:09 AM

macOSandLinuxdifferinuserexperience,technicalaspects,community,andperformance.1)macOSoffersapolished,intuitiveinterfaceidealforaestheticsandeaseofuse.2)Linuxprovidescustomizationandcontrol,appealingtodevelopersandpowerusers.3)macOShasasupportive,inte

macOS vs. Linux: Kernel, Shell, and the CoremacOS vs. Linux: Kernel, Shell, and the CoreApr 20, 2025 am 12:10 AM

There are significant differences between macOS and Linux in terms of kernel, shell and system core: 1. macOS uses the XNU kernel, emphasizing user experience and stability; 2. Linux uses macro kernel, focusing on performance and customization; 3. macOS uses Zsh by default, and Linux has a variety of shell options; 4. macOS system core is highly integrated, while Linux is modular and suitable for customization.

The Most Recent macOS: System Requirements and CompatibilityThe Most Recent macOS: System Requirements and CompatibilityApr 19, 2025 am 12:01 AM

macOSSonoma,releasedin2023,requiresanAppleM1,M2,orIntelCorei5orlater,8GBRAM,35GBstorage,andmacOSBigSur11orlater.ItsupportsMacBook(2017 ),MacBookAir(2018 ),MacBookPro(2017 ),iMac(2017 ),iMacPro(2017),MacPro(2019 ),MacStudio(2022 ),andMacmini(2018 ).

macOS and Linux: Comparing Their Features and FunctionalitymacOS and Linux: Comparing Their Features and FunctionalityApr 18, 2025 am 12:19 AM

macOS is suitable for valuing user experience and hardware and software integration, while Linux is suitable for requiring high customizability and flexibility. macOS is simple and easy to use, seamlessly integrated with Apple products; Linux is open source, adapted to various environments, and has rich community resources.

macOS: Identifying the Most Recent ReleasemacOS: Identifying the Most Recent ReleaseApr 17, 2025 am 12:02 AM

Use the command line tool "sw_vers-productVersion" to identify the latest system version on macOS. 1. Open the terminal and enter the command to get the version number. 2. This command can be used in the script for version comparison and operation. 3. If you need optimization, you can use the "defaultsread" command to read the system file to obtain version information.

macOS Development: Building Native Apps with Swift & XcodemacOS Development: Building Native Apps with Swift & XcodeApr 16, 2025 am 12:01 AM

To develop macOS applications, you need to use Swift and Xcode. 1. Install Xcode and create a new project. 2. Use InterfaceBuilder to design the interface. 3. Write logical code in Swift file. 4. Utilize advanced features such as protocols and generic optimization code. 5. Use debugging tools to resolve common errors. 6. Optimize performance through asynchronous processing.

macOS: The User Experience and DesignmacOS: The User Experience and DesignApr 14, 2025 am 12:02 AM

The design philosophy of macOS is simplicity, user-centered and highly personalized. 1) The simple user interface allows users to quickly find the functions they need; 2) The user-centric design improves the interactive experience; 3) Personalized settings allow the system to be tailored to users; 4) Excellent performance and stability ensure smooth operation of the system; 5) Hidden functions such as shortcut commands and air-to-air playback improve work efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.